29 lines
890 B
Haskell
29 lines
890 B
Haskell
{-# LANGUAGE OverloadedStrings #-}
|
|
module Model.Entry where
|
|
|
|
import Model ( Entry, entryName, entryContent )
|
|
import Model.Markdown ( Markdown(Markdown), unMarkdown )
|
|
import Data.Maybe ( fromMaybe )
|
|
|
|
import qualified Data.Text as T
|
|
import qualified Data.Text.Lazy as TL
|
|
|
|
entryTitle :: Entry -> T.Text
|
|
entryTitle = fromMaybe <$> TL.toStrict . shorten 30 . unMarkdown . entryContent <*> entryName
|
|
|
|
class Shorten a where
|
|
shorten :: Integral n => n -> a -> a
|
|
|
|
instance Shorten T.Text where
|
|
shorten n t
|
|
| T.length t > fromIntegral n = flip T.append "..." . T.take (fromIntegral n - 1) $ t
|
|
| otherwise = t
|
|
|
|
instance Shorten TL.Text where
|
|
shorten n t
|
|
| TL.length t > fromIntegral n = flip TL.append "..." . TL.take (fromIntegral n - 1) $ t
|
|
| otherwise = t
|
|
|
|
instance Shorten Markdown where
|
|
shorten n (Markdown t) = Markdown $ shorten n t
|