properly add the extra metadata to all pages, even tags

This commit is contained in:
Mirek Kratochvil 2023-10-16 13:15:07 +02:00
parent fee144a3ec
commit fca3de03e3
2 changed files with 13 additions and 13 deletions

View file

@ -197,10 +197,11 @@ checkedSubstitute t v = do
-- | Add global information to page metadata for rendering (at this point just the url base) -- | Add global information to page metadata for rendering (at this point just the url base)
addGlobalMeta :: Y.Value -> Site MT.Value addGlobalMeta :: Y.Value -> Site MT.Value
addGlobalMeta (Y.Object m) = do addGlobalMeta meta = do
r <- use urlBase r <- use urlBase
rt <- rootedLink' rt <- rootedLink'
rtp <- rootedPageLink' rtp <- rootedPageLink'
Y.Object m <- (`objMerge` meta) <$> use extraMeta
let l = map (\(k, v) -> (K.toText k, Mu.toMustache v)) $ KM.toList m let l = map (\(k, v) -> (K.toText k, Mu.toMustache v)) $ KM.toList m
pure . Mu.object $ l ++ pure . Mu.object $ l ++
[ ("root", Mu.toMustache $ T.pack r) [ ("root", Mu.toMustache $ T.pack r)
@ -219,17 +220,16 @@ addExtraMeta :: PageInfo -> Y.Value -> Site Y.Value
addExtraMeta pi m = do addExtraMeta pi m = do
metaPath <- metadataFile $ pi ^. pagePath metaPath <- metadataFile $ pi ^. pagePath
metaExists <- io $ doesFileExist metaPath metaExists <- io $ doesFileExist metaPath
gem <- use extraMeta if metaExists
objMerge gem <$> then do
if metaExists io $ putStrLn ("M <- " ++ metaPath)
then do em' <- io $ Y.decodeFileEither metaPath
em' <- io $ Y.decodeFileEither metaPath case em' of
case em' of Left pe ->
Left pe -> error $ "decoding " ++ metaPath ++ " failed: " ++
error $ "decoding " ++ metaPath ++ " failed: " ++ Y.prettyPrintParseException pe
Y.prettyPrintParseException pe Right em -> pure $ objMerge em m
Right em -> pure $ objMerge em m else pure m
else pure m
-- | Add page-specific information to the metadata. In this instance, this just -- | Add page-specific information to the metadata. In this instance, this just
-- expands the tags for rendering and continues by adding extra metadata via -- expands the tags for rendering and continues by adding extra metadata via

View file

@ -15,7 +15,7 @@
{{?subtags}}<h3>Sub-categories</h3> {{?subtags}}<h3>Sub-categories</h3>
<ul> <ul>
{{#subtags}} {{#subtags}}
<li>{{name}} (<a href="{{href}}">{{#htag}} » {{name}} {{/htag}}</a>)</li> <li>{{name}} (<a href="{{href}}">{{#htag}} » {{name}}{{/htag}}</a>)</li>
{{/subtags}} {{/subtags}}
</ul> </ul>
{{/subtags}} {{/subtags}}