aboutsummaryrefslogtreecommitdiff
path: root/Types.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Types.hs')
-rw-r--r--Types.hs19
1 files changed, 18 insertions, 1 deletions
diff --git a/Types.hs b/Types.hs
index bff0491..17be93e 100644
--- a/Types.hs
+++ b/Types.hs
@@ -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" <>