]> source.dussan.org Git - gitea.git/commitdiff
Support custom robots.txt
authorUnknwon <joe2010xtmf@163.com>
Sun, 21 Sep 2014 23:39:10 +0000 (19:39 -0400)
committerUnknwon <joe2010xtmf@163.com>
Sun, 21 Sep 2014 23:39:10 +0000 (19:39 -0400)
cmd/web.go
modules/setting/setting.go

index 83dfca4e6716ac7df1260433fa1f34fbf4a38027..a5ebf259eade054a9b94987fbd99c01404274d48 100644 (file)
@@ -364,6 +364,15 @@ func runWeb(*cli.Context) {
                r.Any("/:reponame/*", ignSignInAndCsrf, repo.Http)
        })
 
+       // robots.txt
+       m.Get("/robots.txt", func(ctx *middleware.Context) {
+               if setting.HasRobotsTxt {
+                       ctx.ServeFile(path.Join(setting.CustomPath, "robots.txt"))
+               } else {
+                       ctx.Error(404)
+               }
+       })
+
        // Not found handler.
        m.NotFound(routers.NotFound)
 
index a1ab43d0222cf2812cd0df98f988e25adf3cb9d9..67e48108d9a072027cf14d41c5f877fc684cd998 100644 (file)
@@ -108,6 +108,7 @@ var (
        ProdMode     bool
        RunUser      string
        IsWindows    bool
+       HasRobotsTxt bool
 )
 
 func init() {
@@ -260,6 +261,8 @@ func NewConfigContext() {
 
        Langs = Cfg.MustValueArray("i18n", "LANGS", ",")
        Names = Cfg.MustValueArray("i18n", "NAMES", ",")
+
+       HasRobotsTxt = com.IsFile(path.Join(CustomPath, "robots.txt"))
 }
 
 var Service struct {