2021-07-23 21:35:02 -04:00
|
|
|
import Text.Pandoc.Definition
|
|
|
|
import qualified Data.Map.Strict as Map
|
|
|
|
import Text.Pandoc.JSON
|
2022-09-17 14:54:16 -04:00
|
|
|
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
|
2022-09-17 14:54:16 -04:00
|
|
|
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"
|