38 lines
709 B
Go
38 lines
709 B
Go
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())
|
|
}
|