blog/blog-meta/nice-date.hs

18 lines
581 B
Haskell
Raw Normal View History

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