add post summaries

This commit is contained in:
rhiannon morris 2024-09-15 17:46:06 +02:00
parent 3ae0cd7c52
commit 7023da3902
3 changed files with 39 additions and 16 deletions

View file

@ -8,7 +8,7 @@ import qualified Data.Text as Text
import Data.Time
import Misc
import qualified YAML
import YAML ((.:), (.!=), (##=))
import YAML ((.:), (.:?), (.!=), (##=))
import qualified System.Console.GetOpt as GetOpt
import qualified System.FilePath.Find as Find
import qualified System.FilePath as Path
@ -69,27 +69,30 @@ getInfo dir file = do
let dirs = Path.splitPath dir
let file' = Path.joinPath $ drop (length dirs) $ Path.splitPath file
unwrap file $ YAML.parseEither $
yaml & YAML.withMap "title, date, tags" \m ->
yaml & YAML.withMap "title, date, tags, summary?" \m ->
Info <$> pure file'
<*> m .: "title"
<*> m .: "date"
<*> m .: "tags" .!= []
<*> m .: "title"
<*> m .: "date"
<*> m .: "tags" .!= []
<*> m .:? "summary"
-- | the front matter info we care about
data PostInfo =
Info {
_nfoFile :: FilePath,
_nfoTitle :: Text,
infoFile :: FilePath,
infoTitle :: Text,
infoDate :: BlogDate,
infoTags :: [Text]
infoTags :: [Text],
infoSummary :: Maybe Text
}
instance YAML.ToYAML PostInfo where
toYAML (Info file title date tags) = YAML.obj
[("date" ##= date),
("title" ##= title),
("tags" ##= tags),
("file" ##= Text.pack (fixup file))]
toYAML (Info file title date tags summary) = YAML.obj
[("date" ##= date),
("title" ##= title),
("tags" ##= tags),
("file" ##= Text.pack (fixup file)),
("summary" ##= summary)]
where fixup f = Path.replaceExtension f "html"
newtype BlogDate = D Day deriving (Eq, Ord)