avoid overwriting timestamps if they are forced by markdown already

This commit is contained in:
Mirek Kratochvil 2023-06-22 11:34:00 +02:00
parent 91900a323c
commit fa7d1fab55
5 changed files with 17 additions and 10 deletions

View file

@ -132,7 +132,8 @@ siteOptions' = do
_timestampSuffix <-
strOption $
long "timestamp-prefix" <>
help "Timestamp file suffix for markdowns" <> value ".timestamp" <> showDefault
help "Timestamp file suffix for markdowns" <>
value ".timestamp" <> showDefault
_dumpFinalState <-
switch $
long "dump-state" <>

View file

@ -2,6 +2,8 @@
mount: /404
title: Page not found
search: off
toc: off
timestamp: null
---
# Page not found!

View file

@ -3,6 +3,7 @@ mount: /
title: Home
template: index.html
toc: off
timestamp: null
---
#### What are How-To Cards?

View file

@ -4,6 +4,7 @@ title: Search
template: search.html
search: off
toc: off
timestamp: null
---
# Search

20
site.hs
View file

@ -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