mirror of
https://github.com/osmarks/mycorrhiza.git
synced 2025-01-05 17:40:26 +00:00
Extract robots.txt into a file, simplify MIMEs
This commit is contained in:
parent
41a5da7f56
commit
190a1d6ba8
6
static/robots.txt
Normal file
6
static/robots.txt
Normal file
@ -0,0 +1,6 @@
|
||||
User-agent: *
|
||||
Allow: /page/
|
||||
Allow: /hypha/
|
||||
Allow: /recent-changes
|
||||
Disallow: /
|
||||
Crawl-delay: 5
|
@ -6,7 +6,7 @@ import (
|
||||
"os"
|
||||
)
|
||||
|
||||
//go:embed *.css *.js icon
|
||||
//go:embed *.css *.js *.txt icon
|
||||
var embedFS embed.FS
|
||||
|
||||
// FS serves all static files.
|
||||
|
21
web/web.go
21
web/web.go
@ -23,7 +23,7 @@ var stylesheets = []string{"default.css", "custom.css"}
|
||||
// httpErr is used by many handlers to signal errors in a compact way.
|
||||
func httpErr(w http.ResponseWriter, status int, name, title, errMsg string) {
|
||||
log.Println(errMsg, "for", name)
|
||||
w.Header().Set("Content-Type", "text/html;charset=utf-8")
|
||||
w.Header().Set("Content-Type", mime.TypeByExtension(".html"))
|
||||
w.WriteHeader(status)
|
||||
fmt.Fprint(
|
||||
w,
|
||||
@ -54,21 +54,20 @@ func handlerStyle(w http.ResponseWriter, rq *http.Request) {
|
||||
}
|
||||
|
||||
func handlerUserList(w http.ResponseWriter, rq *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/html;charset=utf-8")
|
||||
w.Header().Set("Content-Type", mime.TypeByExtension(".html"))
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(views.BaseHTML("User list", views.UserListHTML(), user.FromRequest(rq))))
|
||||
}
|
||||
|
||||
func handlerRobotsTxt(w http.ResponseWriter, rq *http.Request) {
|
||||
w.Header().Set("Content-Type", "text/plain")
|
||||
w.WriteHeader(http.StatusOK)
|
||||
w.Write([]byte(
|
||||
`User-agent: *
|
||||
Allow: /page/
|
||||
Allow: /hypha/
|
||||
Allow: /recent-changes
|
||||
Disallow: /
|
||||
Crawl-delay: 5`))
|
||||
w.Header().Set("Content-Type", "text/plain; charset=utf-8")
|
||||
|
||||
file, err := static.FS.Open("robots.txt")
|
||||
if err != nil {
|
||||
return
|
||||
}
|
||||
io.Copy(w, file)
|
||||
file.Close()
|
||||
}
|
||||
|
||||
func Init() {
|
||||
|
Loading…
Reference in New Issue
Block a user