added redirect anchors

This commit is contained in:
ston1th 2022-03-13 20:36:15 +01:00
commit b13ff70a2d
4 changed files with 44 additions and 18 deletions

View file

@ -37,9 +37,10 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
return
}
fs.log.Info("access",
"uri", r.RequestURI,
"client", r.RemoteAddr,
"method", r.Method,
"status", s.Status(),
"uri", r.RequestURI,
)
}()
upath := r.URL.Path
@ -65,13 +66,11 @@ func (fs *FileServer) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if !d.IsDir() {
if r.FormValue("p") == "t" {
fs.fs.Preload(p)
idx := strings.LastIndex(p, "/")
if idx > 0 {
p = p[:idx]
} else {
p = "/"
rdir := "/"
if i := strings.LastIndex(p, "/"); i > 0 {
rdir = p[:i]
}
http.Redirect(w, r, p, http.StatusFound)
http.Redirect(w, r, rdir+"#"+anchor(p), http.StatusFound)
return
}
if r.FormValue("n") == "t" {