Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Commit 3fc6843

Browse files
committed
chore(code.angularjs.org): improve output of directory listing
1 parent 1e9eadc commit 3fc6843

File tree

1 file changed

+20
-6
lines changed
  • scripts/code.angularjs.org-firebase/functions

1 file changed

+20
-6
lines changed

scripts/code.angularjs.org-firebase/functions/index.js

+20-6
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ function sendStoredFile(request, response) {
3131
}
3232

3333
if (!fileName) {
34-
//Root
34+
// Root
3535
return getDirectoryListing('/').catch(sendErrorResponse);
3636
}
3737

@@ -111,6 +111,11 @@ function sendStoredFile(request, response) {
111111
return getContent(getFilesOptions).then(() => {
112112
let contentList = '';
113113

114+
if (path === '/') {
115+
// Let the latest versions appear first
116+
directoryList.reverse();
117+
}
118+
114119
directoryList.forEach(directoryPath => {
115120
const dirName = directoryPath.split('/').reverse()[1];
116121
contentList += `<a href="${dirName}/">${dirName}/</a><br>`;
@@ -125,11 +130,20 @@ function sendStoredFile(request, response) {
125130
// without trailing slash
126131
const base = request.originalUrl.endsWith('/') ? request.originalUrl : request.originalUrl + '/';
127132

128-
let directoryListing = `
129-
<base href="${base}">
130-
<h1>Index of ${path}</h1>
131-
<hr>
132-
<pre>${contentList}</pre>`;
133+
const directoryListing = `
134+
<!DOCTYPE html>
135+
<html lang="en">
136+
<head>
137+
<meta charset="utf-8" />
138+
<meta name="viewport" content="width=device-width, initial-scale=1">
139+
<base href="${base}">
140+
</head>
141+
<body>
142+
<h1>Index of ${path}</h1>
143+
<hr>
144+
<pre>${contentList}</pre>
145+
</body>
146+
</html>`;
133147

134148
return response
135149
.status(200)

0 commit comments

Comments
 (0)