global metadata

This commit is contained in:
Mirek Kratochvil 2023-06-14 20:54:01 +02:00
parent 0ab1096409
commit 8cb15d3960
2 changed files with 13 additions and 6 deletions

15
site.hs
View file

@ -151,6 +151,12 @@ checkedSubstitute t v = do
--null es `unless` error "template substitution problems"
pure txt
-- | Add global information to page metadata for rendering (at this point just the url base)
addGlobalMeta :: Y.Value -> Site Y.Value
addGlobalMeta (Y.Object m) = do
r <- fromString <$> use urlBase
pure . Y.Object $ KM.insert "root" r m
-- | Render a page using the current template.
installPage :: FilePath -> PageInfo -> Site ()
installPage mount pi = do
@ -160,12 +166,13 @@ installPage mount pi = do
fixedUrlDoc <-
walkURLs (processLink $ pi ^. pagePath . to takeDirectory) $ pi ^. pageDoc
checkTarget file
body <- io . runIOorExplode $ writeHtml5String htmlWriteOpts fixedUrlDoc
let Y.Object meta' = pi ^. pageMeta
meta = Y.Object $ KM.insert "body" (Y.String body) meta'
meta <- addGlobalMeta meta
io $ do
putStrLn $ "P -> " ++ file
makeDirectories file
body <- runIOorExplode $ writeHtml5String htmlWriteOpts fixedUrlDoc
let Y.Object meta' = pi ^. pageMeta
meta = Y.Object $ KM.insert "body" (Y.String body) meta'
checkedSubstitute templ meta >>= TIO.writeFile file
installPageRedirects mount pi
@ -301,7 +308,7 @@ makeTagMeta tag = do
htagMeta <- makeHTagMeta tag
subtagsMeta <- Y.array <$> traverse makeHTagLinkMeta subtags
pagesMeta <- Y.array <$> traverse makePageLinkMeta taggedPages
pure $
addGlobalMeta $
Y.object
[("htag", htagMeta), ("subtags", subtagsMeta), ("pages", pagesMeta)]

View file

@ -7,6 +7,6 @@
All cards {{#htag}} » {{tag}}{{/htag}}
{{/htag}}
</title>
<link rel="stylesheet" href="{{root}}/style.css" />
<link rel="stylesheet" href="{{root}}/fonts.css" />
<link rel="stylesheet" href="{{root}}style.css" />
<link rel="stylesheet" href="{{root}}fonts.css" />
</head>