Pārlūkot izejas kodu

Support custom robots.txt

tags/v0.9.99
Unknwon pirms 9 gadiem
vecāks
revīzija
1273b3d3a9
2 mainītis faili ar 12 papildinājumiem un 0 dzēšanām
  1. 9
    0
      cmd/web.go
  2. 3
    0
      modules/setting/setting.go

+ 9
- 0
cmd/web.go Parādīt failu

@@ -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)


+ 3
- 0
modules/setting/setting.go Parādīt failu

@@ -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 {

Notiek ielāde…
Atcelt
Saglabāt