blog/blog-meta/nice-date.hs
rhiannon morris be46a2fc5c fix tags with spaces
add a filter that replaces tags e.g.
"tag name" → {name: "tag name", slug: "tag_name"}
2022-09-17 20:54:16 +02:00

21 lines
775 B
Haskell

import Text.Pandoc.Definition
import qualified Data.Map.Strict as Map
import Data.Time
import Text.Pandoc.JSON
import Data.Text (unpack, pack)
import Data.Char (toLower)
import Misc
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)) = do
-- extra '-'s in %-m and %-d to allow leading zeroes to be skipped
date <- parseTimeM True defaultTimeLocale "%Y-%-m-%-d" $ unpack txt
let str = formatTime defaultTimeLocale "%A %-e %B %Y" (date :: Day)
pure $ Just $ MetaString $ pack $ map toLower str
reformat (Just d) = fail $ "date is\n" <> show d <> "\nwanted a string"