Skip to content

Commit ab5eeda

Browse files
authored
Add sitemap.xml to improve indexing by search engines (#551)
* Initial draft of sitemap * Add newline * Generate robots.txt * Fix bug * Add newline
1 parent b7ba72f commit ab5eeda

File tree

3 files changed

+38
-0
lines changed

3 files changed

+38
-0
lines changed

message-index/robots.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Sitemap: https://errors.haskell.org/sitemap.xml

message-index/site.hs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,11 @@ main = hakyll $ do
3434
route idRoute
3535
compile copyFileCompiler
3636

37+
-- Necessary to point webcrawlers to the correct sitemap
38+
match "robots.txt" $ do
39+
route idRoute
40+
compile copyFileCompiler
41+
3742
match "images/*" $ do
3843
route idRoute
3944
compile copyFileCompiler
@@ -131,6 +136,27 @@ main = hakyll $ do
131136

132137
match "templates/*" $ compile templateBodyCompiler
133138

139+
create ["sitemap.xml"] $ do
140+
route idRoute
141+
compile $ do
142+
let messages = loadAll "messages/*/*"
143+
let host = "https://errors.haskell.org"
144+
let pageCtx :: Context String
145+
pageCtx =
146+
mconcat
147+
[ modificationTimeField "lastmod" "%Y-%m-%d",
148+
constField "host" host,
149+
defaultContext
150+
]
151+
let sitemapCtx =
152+
mconcat
153+
[ listField "entries" pageCtx messages,
154+
constField "host" host,
155+
defaultContext
156+
]
157+
makeItem ""
158+
>>= loadAndApplyTemplate "templates/sitemap.xml" sitemapCtx
159+
134160
create ["api/errors.json"] $ do
135161
route idRoute
136162
compile $ do

message-index/templates/sitemap.xml

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3+
$for(entries)$
4+
<url>
5+
<loc>$host$$url$</loc>
6+
<changefreq>weekly</changefreq>
7+
$if(lastmod)$<lastmod>$lastmod$</lastmod>$endif$
8+
<priority>0.8</priority>
9+
</url>
10+
$endfor$
11+
</urlset>

0 commit comments

Comments
 (0)