1
0
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:
handlerug 2021-06-23 22:44:27 +07:00
parent 41a5da7f56
commit 190a1d6ba8
No known key found for this signature in database
GPG Key ID: 38009F0605051491
3 changed files with 17 additions and 12 deletions

6
static/robots.txt Normal file
View File

@ -0,0 +1,6 @@
User-agent: *
Allow: /page/
Allow: /hypha/
Allow: /recent-changes
Disallow: /
Crawl-delay: 5

View File

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

View File

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