From 296f7e1a83275a7ad1974baef76f135e05028c30 Mon Sep 17 00:00:00 2001 From: Amneesh Singh Date: Sat, 22 Oct 2022 08:56:48 +0530 Subject: [PATCH] templates: add sitemap.xml Signed-off-by: Amneesh Singh --- src/site.hs | 28 ++++++++++++++++++---------- templates/sitemap.xml | 23 +++++++++++++++++++++++ 2 files changed, 41 insertions(+), 10 deletions(-) create mode 100644 templates/sitemap.xml diff --git a/src/site.hs b/src/site.hs index f0d5796..3145f4e 100644 --- a/src/site.hs +++ b/src/site.hs @@ -13,24 +13,22 @@ import Text.Pandoc.Templates (Template, compileTemplate) main :: IO () main = hakyllWith config $ do - - match "images/logos/*" $ do + let + individualPatterns = fromList ["about.org", "contact.org", "links.org"] + + match "images/**" $ do route idRoute compile copyFileCompiler - + match "fonts/*" $ do route idRoute compile copyFileCompiler - match "sitemap.xml" $ do - route idRoute - compile copyFileCompiler - match "css/*" $ do route idRoute compile compressCssCompiler - match (fromList ["about.org", "contact.org", "links.org"]) $ do + match individualPatterns $ do route $ setExtension "html" compile $ pandocCompiler @@ -103,9 +101,18 @@ main = hakyllWith config $ do posts <- fmap (take 10) . recentFirst =<< loadAllSnapshots "posts/*" "content" renderRss rssFeedConfiguration feedCtx posts - match "images/*" $ do +-- https://robertwpearce.com/hakyll-pt-2-generating-a-sitemap-xml-file.html + create ["sitemap.xml"] $ do route idRoute - compile copyFileCompiler + compile $ do + posts <- recentFirst =<< loadAll "posts/*" + individualPages <- loadAll individualPatterns + let pages = posts <> individualPages + sitemapCtx = + listField "pages" (postCtx tags) (return pages) + <> defaultCtx + makeItem "" + >>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx match "templates/*" $ compile templateBodyCompiler @@ -133,6 +140,7 @@ postCtx tags = tagsField "tags" tags -- <> teaserFieldWithSeparator "((.tease.))" "teaser" "content" <> dateField "date" "%B %e, %Y" + <> dateField "altdate" "%Y-%m-%d" <> modificationTimeField "modified" "%B %e, %Y" <> teaserField "teaser" "content" <> defaultCtx diff --git a/templates/sitemap.xml b/templates/sitemap.xml new file mode 100644 index 0000000..532b7f4 --- /dev/null +++ b/templates/sitemap.xml @@ -0,0 +1,23 @@ + + + + https://$domain$ + daily + 1.0 + +$for(pages)$ + + https://$domain$$url$ + $if(updated)$$updated$$else$$if(altdate)$$altdate$$endif$$endif$ + weekly + 0.8 + +$endfor$ +