Slightly more efficient implementations of Model.Entry.Shorten
This commit is contained in:
parent
940b62b6fc
commit
068ce7a41c
1 changed files with 10 additions and 8 deletions
|
@ -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
|
||||
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
|
||||
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
|
||||
|
|
Loading…
Reference in a new issue