Added sitemaps

This commit is contained in:
Eduard Urbach 2017-11-18 16:01:27 +01:00
parent 54b08453dc
commit 567aff76f9
2 changed files with 39 additions and 1 deletions

View File

@ -4,6 +4,8 @@ import (
"io/ioutil"
"github.com/aerogo/aero"
"github.com/aerogo/sitemap"
"github.com/animenotifier/arn"
"github.com/animenotifier/notify.moe/components/js"
)
@ -52,6 +54,42 @@ func configureAssets(app *aero.Application) {
return ctx.File("videos" + ctx.Get("file"))
})
// Anime sitemap
app.Get("/sitemap/anime.txt", func(ctx *aero.Context) string {
sitemap := sitemap.New()
prefix := "https://" + app.Config.Domain
for anime := range arn.StreamAnime() {
sitemap.Add(prefix + anime.Link())
}
return ctx.Text(sitemap.Text())
})
// Character sitemap
app.Get("/sitemap/character.txt", func(ctx *aero.Context) string {
sitemap := sitemap.New()
prefix := "https://" + app.Config.Domain
for character := range arn.StreamCharacters() {
sitemap.Add(prefix + character.Link())
}
return ctx.Text(sitemap.Text())
})
// User sitemap
app.Get("/sitemap/user.txt", func(ctx *aero.Context) string {
sitemap := sitemap.New()
prefix := "https://" + app.Config.Domain
for user := range arn.StreamUsers() {
sitemap.Add(prefix + user.Link())
}
return ctx.Text(sitemap.Text())
})
// For benchmarks
app.Get("/hello", func(ctx *aero.Context) string {
return ctx.Text("Hello World")

View File

@ -68,7 +68,7 @@ func logRequest(ctx *aero.Context, responseTime time.Duration) {
// Notify us about long requests.
// However ignore requests under /auth/ because those depend on 3rd party servers.
if responseTime >= 200*time.Millisecond && !strings.HasPrefix(ctx.URI(), "/auth/") {
if responseTime >= 300*time.Millisecond && !strings.HasPrefix(ctx.URI(), "/auth/") {
err.Error("Long response time", ip, hostName, responseTimeString, ctx.StatusCode, ctx.URI())
}
}