Allow directory listing work with or without trailing slash (removing trailing slash by default), and make directory listing links absolute instead of relative

This commit is contained in:
Micah Lee 2020-11-23 14:52:52 -08:00
parent 8a45de8241
commit e950cc5fe8
3 changed files with 75 additions and 60 deletions

View file

@ -71,6 +71,9 @@ class WebsiteModeWeb(SendBaseModeWeb):
self.web.cancel_compression = True
def render_logic(self, path=""):
# Strip trailing slash
path = path.rstrip("/")
if path in self.files:
filesystem_path = self.files[path]
@ -86,10 +89,7 @@ class WebsiteModeWeb(SendBaseModeWeb):
# Otherwise, render directory listing
filenames = []
for filename in os.listdir(filesystem_path):
if os.path.isdir(os.path.join(filesystem_path, filename)):
filenames.append(filename + "/")
else:
filenames.append(filename)
filenames.append(filename)
filenames.sort()
return self.directory_listing(filenames, path, filesystem_path)