From c86ece1433da3e8a85d84233f236a7d3b7945534 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Thu, 22 Jun 2023 11:43:20 +0200 Subject: implement sourcing of timestamp files --- Types.hs | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index 58a8197..455a4f4 100644 --- a/Types.hs +++ b/Types.hs @@ -58,6 +58,7 @@ data SiteState = , _redirectTemplate :: FilePath -- ^ Name of the template for redirect pages , _tagTemplate :: FilePath -- ^ Name of the template for category pages , _listTemplate :: FilePath -- ^ Name of the template for listing pages + , _timestampSuffix :: FilePath -- ^ File to search for a timestamp (e.g., if the prefix is ".ts", a timestamp for file "page.md" will be looked for in "page.md.ts"). These are best autogenerated with a script that sources the data from git or so. , _urlBase :: FilePath -- ^ "Root route" to prepend to all absolute links. , _dumpFinalState :: Bool -- ^ Triggers printing out the structure when the processing finishes. } @@ -128,6 +129,10 @@ siteOptions' = do strOption $ long "url-base" <> short 'u' <> help "Base absolute URL" <> value "/" <> showDefault + _timestampSuffix <- + strOption $ + long "timestamp-prefix" <> + help "Timestamp file suffix for markdowns" <> value ".timestamp" <> showDefault _dumpFinalState <- switch $ long "dump-state" <> -- cgit v1.2.3 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 --- Types.hs | 3 ++- cards/404.md | 2 ++ cards/index.md | 1 + cards/search.md | 1 + site.hs | 20 +++++++++++--------- 5 files changed, 17 insertions(+), 10 deletions(-) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index 455a4f4..7f09b05 100644 --- a/Types.hs +++ b/Types.hs @@ -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" <> diff --git a/cards/404.md b/cards/404.md index 60148b7..a0e09ea 100644 --- a/cards/404.md +++ b/cards/404.md @@ -2,6 +2,8 @@ mount: /404 title: Page not found search: off +toc: off +timestamp: null --- # Page not found! diff --git a/cards/index.md b/cards/index.md index b493711..fb19e6e 100644 --- a/cards/index.md +++ b/cards/index.md @@ -3,6 +3,7 @@ mount: / title: Home template: index.html toc: off +timestamp: null --- #### What are How-To Cards? diff --git a/cards/search.md b/cards/search.md index cefd3eb..42713f0 100644 --- a/cards/search.md +++ b/cards/search.md @@ -4,6 +4,7 @@ title: Search template: search.html search: off toc: off +timestamp: null --- # Search 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