diff --git a/src/Model/Entry.hs b/src/Model/Entry.hs index 97d64ff..f2a4b59 100644 --- a/src/Model/Entry.hs +++ b/src/Model/Entry.hs @@ -9,20 +9,22 @@ 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 +entryTitle = fromMaybe <$> TL.toStrict . unMarkdown . shorten 30 . entryContent <*> entryName class Shorten a where - shorten :: Integral n => n -> a -> a + shorten :: Int -> 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 + shorten i t + | T.compareLength t n == GT = flip T.append "..." . T.take (n - 1) $ t + | otherwise = t + where n = fromIntegral i instance Shorten TL.Text where - shorten n t - | TL.length t > fromIntegral n = flip TL.append "..." . TL.take (fromIntegral n - 1) $ t - | otherwise = t + shorten i t + | TL.compareLength t n == GT = flip TL.append "..." . TL.take (n - 1) $ t + | otherwise = t + where n = fromIntegral i instance Shorten Markdown where shorten n (Markdown t) = Markdown $ shorten n t