Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add sitemap.xml to improve indexing by search engines #551

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions message-index/robots.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sitemap: https://errors.haskell.org/sitemap.xml
26 changes: 26 additions & 0 deletions message-index/site.hs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -131,6 +136,27 @@ 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,
defaultContext
]
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
Expand Down
11 changes: 11 additions & 0 deletions message-index/templates/sitemap.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
$for(entries)$
<url>
<loc>$host$$url$</loc>
<changefreq>weekly</changefreq>
$if(lastmod)$<lastmod>$lastmod$</lastmod>$endif$
<priority>0.8</priority>
</url>
$endfor$
</urlset>
Loading