1
0
Fork 0

Add trailing slash to subdirectory links in directory listings.

This commit is contained in:
Solderpunk 2020-07-30 18:49:59 +02:00
parent b26fb875a7
commit 02dc6a82c6

View file

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