Browse Source

Add trailing slash to subdirectory links in directory listings.

master
Solderpunk 1 year ago
parent
commit
02dc6a82c6
  1. 8
      dirlist.go

8
dirlist.go

@ -60,7 +60,13 @@ func generateDirectoryListing(URL *url.URL, path string, config Config) (string,
if uint64(file.Mode().Perm())&0444 != 0444 {
continue
}
listing += fmt.Sprintf("=> %s %s\n", url.PathEscape(file.Name()), generatePrettyFileLabel(file, path, config))
// Make sure links to directories have a trailing slash,
// to avoid needless redirects
relativeUrl := url.PathEscape(file.Name())
if file.IsDir() {
relativeUrl += "/"
}
listing += fmt.Sprintf("=> %s %s\n", relativeUrl, generatePrettyFileLabel(file, path, config))
}
return listing, nil
}

Loading…
Cancel
Save