From fa7d1fab5550822b1f4cad753f122515a818a600 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Thu, 22 Jun 2023 11:34:00 +0200 Subject: avoid overwriting timestamps if they are forced by markdown already --- site.hs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) (limited to 'site.hs') diff --git a/site.hs b/site.hs index 7989dff..d60486e 100644 --- a/site.hs +++ b/site.hs @@ -182,15 +182,17 @@ timestampFile fp = do -- | If a timestamp file for the page exists, add the timestamp metadata. addTimeMeta :: PageInfo -> Y.Value -> Site Y.Value -addTimeMeta pi m'@(Y.Object m) = do - tspath <- timestampFile $ pi ^. pagePath - io $ - ifM - (doesFileExist tspath) - (do putStrLn $ "timestamp <- " ++ tspath - ts <- Y.String <$> TIO.readFile tspath - pure . Y.Object $ KM.insert "timestamp" ts m) - (pure m') +addTimeMeta pi m'@(Y.Object m) + | "timestamp" `KM.member` m = pure m' -- do not overwrite the timestamp if present + | otherwise = do + tspath <- timestampFile $ pi ^. pagePath + io $ + ifM + (doesFileExist tspath) + (do putStrLn $ "timestamp <- " ++ tspath + ts <- Y.String <$> TIO.readFile tspath + pure . Y.Object $ KM.insert "timestamp" ts m) + (pure m') -- | Add page-specific information to the metadata. In this instance, this just -- expands the tags for rendering. Eventually would be nice to have the timestamps -- cgit v1.2.3