Added a sitemap
This commit is contained in:
parent
f8464eabf3
commit
ee6ab6f00d
1
main.go
1
main.go
@ -22,5 +22,6 @@ func main() {
|
||||
server.Get("/", pages.Frontpage)
|
||||
server.Get("/blog", pages.Blog)
|
||||
server.Get("/:post", pages.Post)
|
||||
server.Get("/sitemap.txt", pages.Sitemap)
|
||||
server.Run(address)
|
||||
}
|
||||
|
38
server/pages/Sitemap.go
Normal file
38
server/pages/Sitemap.go
Normal file
@ -0,0 +1,38 @@
|
||||
package pages
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"sort"
|
||||
|
||||
"git.urbach.dev/go/web"
|
||||
"git.urbach.dev/go/web/send"
|
||||
"git.urbach.dev/web/urbach.dev/server/app"
|
||||
)
|
||||
|
||||
func Sitemap(ctx web.Context) error {
|
||||
html := bytes.Buffer{}
|
||||
html.WriteString("https://urbach.dev\n")
|
||||
html.WriteString("https://urbach.dev/blog\n")
|
||||
|
||||
articles := []*app.Post{}
|
||||
|
||||
for _, post := range app.Posts {
|
||||
if !post.Published {
|
||||
continue
|
||||
}
|
||||
|
||||
articles = append(articles, post)
|
||||
}
|
||||
|
||||
sort.Slice(articles, func(i, j int) bool {
|
||||
return articles[i].Created > articles[j].Created
|
||||
})
|
||||
|
||||
for _, post := range articles {
|
||||
html.WriteString("https://urbach.dev/")
|
||||
html.WriteString(post.Slug)
|
||||
html.WriteByte('\n')
|
||||
}
|
||||
|
||||
return send.Text(ctx, html.String())
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user