From eeb4696a91788a560d6097472099a658ad9918d4 Mon Sep 17 00:00:00 2001 From: Mirek Kratochvil Date: Fri, 13 Oct 2023 22:37:09 +0200 Subject: implement ingesting the extra metadata from files, reorganize a bit --- Types.hs | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) (limited to 'Types.hs') diff --git a/Types.hs b/Types.hs index 6e83304..4e1e037 100644 --- a/Types.hs +++ b/Types.hs @@ -29,6 +29,7 @@ import Lens.Micro.TH import Options.Applicative import qualified Text.Mustache as Mu import qualified Text.Pandoc.Definition +import AesonUtils -- | Information about a single deployed page (with metadata etc). data PageInfo = @@ -73,8 +74,8 @@ 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 - , _extraMeta :: [(String, Y.Value)] -- ^ Extra metadata added to rendering of all templates - , _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. + , _extraMeta :: Y.Value -- ^ Extra metadata added to rendering of all templates + , _metadataSuffix :: FilePath -- ^ File suffix to search for a extra metadata (e.g., if the suffix is ".extra", the extra metadata for file "page.md" will be looked for in "page.md.extra"). 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. , _appendUrlIndex :: Bool -- ^ Append full @index.html@ to all page URLs , _dumpFinalState :: Bool -- ^ Triggers printing out the structure when the processing finishes. @@ -140,26 +141,23 @@ siteOptions' = do long "list-template" <> help "Template for making tag-listing pages" <> value "list.html" <> showDefault - _timestampSuffix <- + _metadataSuffix <- strOption $ - long "timestamp-suffix" <> - help "Timestamp file suffix for markdowns" <> - value ".timestamp" <> showDefault + long "metadata-suffix" <> + help "Suffix for YAML files with base metadata for each markdown page. Metadata from files override the extra metadata specified on commandline, but are overriden by metadata specified directly in the markdown header." <> + value ".metadata.yml" <> showDefault _extraMeta <- - let processKeyVal :: String -> (String, Y.Value) + let processKeyVal :: String -> Y.Value processKeyVal opt = - case break (== ':') opt of - (k, ':':v) -> - case Y.decodeEither' $ Data.ByteString.UTF8.fromString v of - Right v -> (k, v :: Y.Value) - Left err -> - error $ - "cannot parse key:val in --extra-metadata: " ++ show err - _ -> error "cannot process key:val in --extra-metadata" - in fmap (map processKeyVal) . many . strOption $ + case Y.decodeEither' $ Data.ByteString.UTF8.fromString opt of + Right v -> v + Left err -> + error $ + "cannot parse YAML in --extra-metadata: " ++ Y.prettyPrintParseException err + in fmap (foldl objMerge Y.Null . map processKeyVal) . many . strOption $ long "extra-metadata" <> help - "Extra metadata to add to pages rendering in format `key:'. May be specified multiple times." + "Extra metadata to add to pages rendering in YAML format. May be specified multiple times." _urlBase <- strOption $ long "url-base" <> -- cgit v1.2.3