Skip to content

Commit 752ba0d

Browse files
committed
add robots.txt and sitemap.xml
1 parent dbf71a3 commit 752ba0d

3 files changed

Lines changed: 20 additions & 0 deletions

File tree

main.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,15 @@ func main() {
8080
loadData()
8181

8282
http.Handle("/static/", http.StripPrefix("/static/", http.FileServer(http.Dir("static"))))
83+
84+
// Serve robots.txt and sitemap.xml at the site root to aid crawlers
85+
http.HandleFunc("/robots.txt", func(w http.ResponseWriter, r *http.Request) {
86+
http.ServeFile(w, r, "static/robots.txt")
87+
})
88+
http.HandleFunc("/sitemap.xml", func(w http.ResponseWriter, r *http.Request) {
89+
http.ServeFile(w, r, "static/sitemap.xml")
90+
})
91+
8392
http.HandleFunc("/", homeHandler)
8493
http.HandleFunc("/draw/create", createDrawHandler)
8594
http.HandleFunc("/draw/", drawHandler)

static/robots.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
User-agent: *
2+
Allow: /
3+
Sitemap: https://secret-santa-draw.app/sitemap.xml

static/sitemap.xml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">
3+
<url>
4+
<loc>https://secret-santa-draw.app/draw/create</loc>
5+
<changefreq>weekly</changefreq>
6+
<priority>0.8</priority>
7+
</url>
8+
</urlset>

0 commit comments

Comments
 (0)