diff options
author | Xinyu Zhou <its@baronbunny.cn> | 2022-10-28 23:17:38 +0800 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-10-28 11:17:38 -0400 |
commit | 100448a007707c049a769cb71cd170fcb5b64a25 (patch) | |
tree | 2e46e2d5b942906d87d0be3af7f882501c28c5bf /routers/web | |
parent | cd5c067abe6b3d33a35ec6904abc91a0b18edfd9 (diff) | |
download | gitea-100448a007707c049a769cb71cd170fcb5b64a25.tar.gz gitea-100448a007707c049a769cb71cd170fcb5b64a25.zip |
Allow disable sitemap (#21617)
This patch provide a mechanism to disable
[sitemap](https://github.com/go-gitea/gitea/pull/18407).
Signed-off-by: Xinyu Zhou <i@sourcehut.net>
Co-authored-by: 6543 <6543@obermui.de>
Diffstat (limited to 'routers/web')
-rw-r--r-- | routers/web/web.go | 13 |
1 files changed, 10 insertions, 3 deletions
diff --git a/routers/web/web.go b/routers/web/web.go index 9b814c3f54..0b16e756e1 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -296,12 +296,19 @@ func RegisterRoutes(m *web.Route) { } } + sitemapEnabled := func(ctx *context.Context) { + if !setting.EnableSitemap { + ctx.Error(http.StatusNotFound) + return + } + } + // FIXME: not all routes need go through same middleware. // Especially some AJAX requests, we can reduce middleware number to improve performance. // Routers. // for health check m.Get("/", Home) - m.Get("/sitemap.xml", ignExploreSignIn, HomeSitemap) + m.Get("/sitemap.xml", sitemapEnabled, ignExploreSignIn, HomeSitemap) m.Group("/.well-known", func() { m.Get("/openid-configuration", auth.OIDCWellKnown) m.Group("", func() { @@ -318,9 +325,9 @@ func RegisterRoutes(m *web.Route) { ctx.Redirect(setting.AppSubURL + "/explore/repos") }) m.Get("/repos", explore.Repos) - m.Get("/repos/sitemap-{idx}.xml", explore.Repos) + m.Get("/repos/sitemap-{idx}.xml", sitemapEnabled, explore.Repos) m.Get("/users", explore.Users) - m.Get("/users/sitemap-{idx}.xml", explore.Users) + m.Get("/users/sitemap-{idx}.xml", sitemapEnabled, explore.Users) m.Get("/organizations", explore.Organizations) m.Get("/code", explore.Code) m.Get("/topics/search", explore.TopicSearch) |