Add trailing slash to subdirectory links in directory listings.
This commit is contained in:
parent
b26fb875a7
commit
02dc6a82c6
1 changed files with 7 additions and 1 deletions
|
@ -60,7 +60,13 @@ func generateDirectoryListing(URL *url.URL, path string, config Config) (string,
|
||||||
if uint64(file.Mode().Perm())&0444 != 0444 {
|
if uint64(file.Mode().Perm())&0444 != 0444 {
|
||||||
continue
|
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
|
return listing, nil
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue