Make entry names optional, since notes shouldn't have names and articles should

This commit is contained in:
Danielle McLean 2017-10-11 23:34:36 +11:00
parent 10b1ed834a
commit fa992bc861
Signed by: 00dani
GPG key ID: 5A5D2D1AFF12EEC5
6 changed files with 24 additions and 5 deletions

15
src/Model/Entry.hs Normal file
View file

@ -0,0 +1,15 @@
{-# LANGUAGE OverloadedStrings #-}
module Model.Entry where
import Model ( Entry, entryName, entryContent )
import Data.Maybe ( fromMaybe )
import qualified Data.Text as T
entryTitle :: Entry -> T.Text
entryTitle = fromMaybe <$> shorten 30 . entryContent <*> entryName
shorten :: Int -> T.Text -> T.Text
shorten n t
| T.length t > n = flip T.append "..." . T.take (n - 1) $ t
| otherwise = t