Skip to content

Commit

Permalink
fix: use same directory listing format as nginx
Browse files Browse the repository at this point in the history
  • Loading branch information
flakey5 committed Nov 13, 2023
1 parent b854489 commit c42ce71
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 41 deletions.
12 changes: 1 addition & 11 deletions src/handlers/strategies/directoryListing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,7 @@ export function renderDirectoryListing(
env: Env
): Response {
// Holds the contents of the listing (directories and files)
const tableElements = [];

// There shouldn't really be a case where we're listing the root
// directory (/) when this is deployed, so always add the option
// to go up a directory
tableElements.push({
href: '../',
name: '../',
lastModified: '-',
size: '-',
});
const tableElements: object[] = [];

const urlPathname = `${url.pathname}${url.pathname.endsWith('/') ? '' : '/'}`;

Expand Down
36 changes: 7 additions & 29 deletions src/templates/directoryListing.hbs
Original file line number Diff line number Diff line change
@@ -1,31 +1,9 @@
<html>
<head>
<title>Index of {{pathname}}</title>
<meta name='viewport' content='width=device-width, initial-scale=1.0' />
<meta charset='utf-8' />
<style type='text/css'>
td { padding-right: 16px; text-align: right; font-family: monospace }
td:nth-of-type(1) { text-align: left; overflow-wrap: anywhere }
td:nth-of-type(3) { white-space: nowrap } th { text-align: left; } @media
(prefers-color-scheme: dark) { body { color: white; background-color:
#1c1b22; } a { color: #3391ff; } a:visited { color: #C63B65; } }
</style>
</head>
<body>
<h1>Index of {{pathname}}</h1>
<table>
<tr>
<th>Filename</th>
<th>Modified</th>
<th>Size</th>
</tr>
{{#each entries}}
<tr>
<td><a href='{{href}}'>{{name}}</a></td>
<td>{{lastModified}}</td>
<td>{{size}}</td>
</tr>
{{/each}}
</table>
</body>
<head><title>Index of {{pathname}}</title></head>
<body>
<h1>Index of {{pathname}}</h1><hr><pre><a href="../">../</a><br />
{{#each entries}}
<a href="{{href}}">{{name}}</a> {{lastModified}} {{size}}<br />
{{/each}}
</pre><hr></body>
</html>
2 changes: 1 addition & 1 deletion src/templates/directoryListing.out.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit c42ce71

Please sign in to comment.