blog/blog-meta/nice-date.hs

18 lines
581 B
Haskell

import Text.Pandoc.Definition
import qualified Data.Map.Strict as Map
import Text.Pandoc.JSON
import Misc
-- | replaces the @date@ field, which starts in YYYY-MM-DD format, with
-- something prettier
main :: IO ()
main = toJSONFilter \(Pandoc (Meta m) body) -> do
m' <- Map.alterF reformat "date" m
pure $ Pandoc (Meta m') body
reformat :: Maybe MetaValue -> IO (Maybe MetaValue)
reformat Nothing = pure Nothing
reformat (Just (toText -> Just txt)) =
Just . MetaString . showDate <$> parseIsoDate txt
reformat (Just d) = fail $ "date is\n" <> show d <> "\nwanted a string"