From 55a62916e434725d8ab9f02b189a9ae9883f6ce5 Mon Sep 17 00:00:00 2001 From: David Binder Date: Sat, 28 Dec 2024 13:43:57 +0100 Subject: [PATCH 1/5] Initial draft of sitemap --- message-index/site.hs | 20 ++++++++++++++++++++ message-index/templates/sitemap.xml | 11 +++++++++++ 2 files changed, 31 insertions(+) create mode 100644 message-index/templates/sitemap.xml diff --git a/message-index/site.hs b/message-index/site.hs index 240b54d..747a44e 100644 --- a/message-index/site.hs +++ b/message-index/site.hs @@ -131,6 +131,26 @@ main = hakyll $ do match "templates/*" $ compile templateBodyCompiler + create ["sitemap.xml"] $ do + route idRoute + compile $ do + let messages = loadAll "messages/*/*" + let host = "https://errors.haskell.org" + let pageCtx :: Context String + pageCtx = + mconcat + [ modificationTimeField "lastmod" "%Y-%m-%d", + constField "host" host + ] + let sitemapCtx = + mconcat + [ listField "entries" pageCtx messages, + constField "host" host, + defaultContext + ] + makeItem "" + >>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx + create ["api/errors.json"] $ do route idRoute compile $ do diff --git a/message-index/templates/sitemap.xml b/message-index/templates/sitemap.xml new file mode 100644 index 0000000..564d72b --- /dev/null +++ b/message-index/templates/sitemap.xml @@ -0,0 +1,11 @@ + + +$for(entries)$ + + $host$$url$ + weekly + $if(lastmod)$$lastmod$$endif$ + 0.8 + +$endfor$ + \ No newline at end of file From 014a96d63ffe103c38b2020da9effd0b08989382 Mon Sep 17 00:00:00 2001 From: David Binder Date: Sat, 28 Dec 2024 13:53:25 +0100 Subject: [PATCH 2/5] Add newline --- message-index/templates/sitemap.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/message-index/templates/sitemap.xml b/message-index/templates/sitemap.xml index 564d72b..f8836e7 100644 --- a/message-index/templates/sitemap.xml +++ b/message-index/templates/sitemap.xml @@ -8,4 +8,4 @@ $for(entries)$ 0.8 $endfor$ - \ No newline at end of file + From bf1a99c7682714cf079afff1795c3e9def716931 Mon Sep 17 00:00:00 2001 From: David Binder Date: Sat, 28 Dec 2024 14:13:26 +0100 Subject: [PATCH 3/5] Generate robots.txt --- message-index/robots.txt | 1 + message-index/site.hs | 5 +++++ 2 files changed, 6 insertions(+) create mode 100644 message-index/robots.txt diff --git a/message-index/robots.txt b/message-index/robots.txt new file mode 100644 index 0000000..80f62b3 --- /dev/null +++ b/message-index/robots.txt @@ -0,0 +1 @@ +Sitemap: https://errors.haskell.org/sitemap.xml \ No newline at end of file diff --git a/message-index/site.hs b/message-index/site.hs index 747a44e..dc1a06b 100644 --- a/message-index/site.hs +++ b/message-index/site.hs @@ -34,6 +34,11 @@ main = hakyll $ do route idRoute compile copyFileCompiler + -- Necessary to point webcrawlers to the correct sitemap + match "robots.txt" $ do + route idRoute + compile copyFileCompiler + match "images/*" $ do route idRoute compile copyFileCompiler From 0a5c7e883ca3f5ca7a61d04b3551ab0676aa46f0 Mon Sep 17 00:00:00 2001 From: David Binder Date: Sat, 28 Dec 2024 14:19:02 +0100 Subject: [PATCH 4/5] Fix bug --- message-index/site.hs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/message-index/site.hs b/message-index/site.hs index dc1a06b..edc527c 100644 --- a/message-index/site.hs +++ b/message-index/site.hs @@ -145,7 +145,8 @@ main = hakyll $ do pageCtx = mconcat [ modificationTimeField "lastmod" "%Y-%m-%d", - constField "host" host + constField "host" host, + defaultContext ] let sitemapCtx = mconcat From 56f345133a2ab8a3ffc61826cb91a92fe0a8ce1d Mon Sep 17 00:00:00 2001 From: David Binder Date: Sat, 28 Dec 2024 14:22:08 +0100 Subject: [PATCH 5/5] Add newline --- message-index/robots.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/message-index/robots.txt b/message-index/robots.txt index 80f62b3..d8ed6a2 100644 --- a/message-index/robots.txt +++ b/message-index/robots.txt @@ -1 +1 @@ -Sitemap: https://errors.haskell.org/sitemap.xml \ No newline at end of file +Sitemap: https://errors.haskell.org/sitemap.xml