Skip to content

Commit

Permalink
Add sitemap.xml to improve indexing by search engines (#551)
Browse files Browse the repository at this point in the history
* Initial draft of sitemap

* Add newline

* Generate robots.txt

* Fix bug

* Add newline
  • Loading branch information
BinderDavid authored Feb 2, 2025
1 parent b7ba72f commit ab5eeda
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 0 deletions.
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>

0 comments on commit ab5eeda

Please sign in to comment.