GoBlog/robotstxt.go

30 lines
784 B
Go
Raw Permalink Normal View History

package main
import (
"fmt"
"net/http"
)
const robotsTXTPath = "/robots.txt"
2022-02-25 15:29:42 +00:00
func (a *goBlog) serveRobotsTXT(w http.ResponseWriter, _ *http.Request) {
_, _ = fmt.Fprint(w, "User-agent: *\n")
if a.isPrivate() {
_, _ = fmt.Fprint(w, "Disallow: /\n")
return
}
_, _ = fmt.Fprint(w, "Allow: /\n\n")
if a.cfg.RobotsTxt != nil && len(a.cfg.RobotsTxt.BlockedBots) != 0 {
for _, bot := range a.cfg.RobotsTxt.BlockedBots {
_, _ = fmt.Fprint(w, "User-agent: ")
_, _ = fmt.Fprint(w, bot)
_, _ = fmt.Fprint(w, "\n")
_, _ = fmt.Fprint(w, "Disallow: /\n\n")
}
}
_, _ = fmt.Fprintf(w, "Sitemap: %s\n", a.getFullAddress(sitemapPath))
for _, bc := range a.cfg.Blogs {
_, _ = fmt.Fprintf(w, "Sitemap: %s\n", a.getFullAddress(bc.getRelativePath(sitemapBlogPath)))
}
}