diff options
| author | Mirek Kratochvil <miroslav.kratochvil@uni.lu> | 2023-08-03 14:12:18 +0200 |
|---|---|---|
| committer | Mirek Kratochvil <miroslav.kratochvil@uni.lu> | 2023-08-03 14:12:18 +0200 |
| commit | b4bbc0f1b3e20bd21210c7786880d0fc337303b8 (patch) | |
| tree | 429bd61460b840611c51b33f64f262d6c8ca846c /Types.hs | |
| parent | 8d2c3c229cc4b3025de70a4892ad99c6be33caa2 (diff) | |
| download | reploy-b4bbc0f1b3e20bd21210c7786880d0fc337303b8.tar.gz reploy-b4bbc0f1b3e20bd21210c7786880d0fc337303b8.tar.bz2 | |
support custom metadata per build
Closes #13
Diffstat (limited to 'Types.hs')
| -rw-r--r-- | Types.hs | 19 |
1 files changed, 18 insertions, 1 deletions
@@ -21,7 +21,8 @@ module Types where import Control.Monad.Trans.State.Lazy -import Data.List.NonEmpty +import qualified Data.ByteString.UTF8 +import Data.List.NonEmpty (nonEmpty, toList) import qualified Data.Map as M import qualified Data.Set as S import qualified Data.Yaml as Y @@ -73,6 +74,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 + , _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. , _urlBase :: FilePath -- ^ "Root route" to prepend to all absolute links. , _appendUrlIndex :: Bool -- ^ Append full @index.html@ to all page URLs @@ -146,6 +148,21 @@ siteOptions' = do long "timestamp-prefix" <> help "Timestamp file suffix for markdowns" <> value ".timestamp" <> showDefault + _extraMeta <- + let processKeyVal :: String -> (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 $ + long "extra-metadata" <> + help + "Extra metadata to add to pages rendering in format `key:<yaml>'. May be specified multiple times." _urlBase <- strOption $ long "url-base" <> |
