Skip to content

Commit 100448a

Browse files
Xinyu Zhou6543
Xinyu Zhou
andauthored
Allow disable sitemap (#21617)
This patch provide a mechanism to disable [sitemap](#18407). Signed-off-by: Xinyu Zhou <[email protected]> Co-authored-by: 6543 <[email protected]>
1 parent cd5c067 commit 100448a

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

custom/conf/app.example.ini

+2-1
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,8 @@ ROUTER = console
21962196
;SHOW_FOOTER_VERSION = true
21972197
;; Show template execution time in the footer
21982198
;SHOW_FOOTER_TEMPLATE_LOAD_TIME = true
2199-
2199+
;; Generate sitemap. Defaults to `true`.
2200+
; ENABLE_SITEMAP = true
22002201

22012202
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22022203
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

+1
Original file line numberDiff line numberDiff line change
@@ -1233,3 +1233,4 @@ PROXY_HOSTS = *.github.com
12331233
- `SHOW_FOOTER_BRANDING`: **false**: Show Gitea branding in the footer.
12341234
- `SHOW_FOOTER_VERSION`: **true**: Show Gitea and Go version information in the footer.
12351235
- `SHOW_FOOTER_TEMPLATE_LOAD_TIME`: **true**: Show time of template execution in the footer.
1236+
- `ENABLE_SITEMAP`: **true**: Generate sitemap.

modules/setting/setting.go

+2
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ var (
452452
RunUser string
453453
IsWindows bool
454454
HasRobotsTxt bool
455+
EnableSitemap bool
455456
InternalToken string // internal access token
456457
)
457458

@@ -1100,6 +1101,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
11001101
ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool(false)
11011102
ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool(true)
11021103
ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true)
1104+
EnableSitemap = Cfg.Section("other").Key("ENABLE_SITEMAP").MustBool(true)
11031105

11041106
UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true)
11051107
UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)

routers/web/web.go

+10-3
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,19 @@ func RegisterRoutes(m *web.Route) {
296296
}
297297
}
298298

299+
sitemapEnabled := func(ctx *context.Context) {
300+
if !setting.EnableSitemap {
301+
ctx.Error(http.StatusNotFound)
302+
return
303+
}
304+
}
305+
299306
// FIXME: not all routes need go through same middleware.
300307
// Especially some AJAX requests, we can reduce middleware number to improve performance.
301308
// Routers.
302309
// for health check
303310
m.Get("/", Home)
304-
m.Get("/sitemap.xml", ignExploreSignIn, HomeSitemap)
311+
m.Get("/sitemap.xml", sitemapEnabled, ignExploreSignIn, HomeSitemap)
305312
m.Group("/.well-known", func() {
306313
m.Get("/openid-configuration", auth.OIDCWellKnown)
307314
m.Group("", func() {
@@ -318,9 +325,9 @@ func RegisterRoutes(m *web.Route) {
318325
ctx.Redirect(setting.AppSubURL + "/explore/repos")
319326
})
320327
m.Get("/repos", explore.Repos)
321-
m.Get("/repos/sitemap-{idx}.xml", explore.Repos)
328+
m.Get("/repos/sitemap-{idx}.xml", sitemapEnabled, explore.Repos)
322329
m.Get("/users", explore.Users)
323-
m.Get("/users/sitemap-{idx}.xml", explore.Users)
330+
m.Get("/users/sitemap-{idx}.xml", sitemapEnabled, explore.Users)
324331
m.Get("/organizations", explore.Organizations)
325332
m.Get("/code", explore.Code)
326333
m.Get("/topics/search", explore.TopicSearch)

0 commit comments

Comments
 (0)