2021-07-23 21:35:02 -04:00
|
|
|
import Text.Pandoc.Definition
|
|
|
|
import qualified Data.Map.Strict as Map
|
|
|
|
import Data.Time
|
|
|
|
import Text.Pandoc.JSON
|
2022-09-17 14:54:16 -04:00
|
|
|
import Data.Text (unpack, pack)
|
2021-07-23 21:35:02 -04:00
|
|
|
import Data.Char (toLower)
|
2022-09-17 14:54:16 -04:00
|
|
|
import Misc
|
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
|
|
|
|
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"
|