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

Commit

Permalink
chore(code.angularjs.org): improve output of directory listing
Browse files Browse the repository at this point in the history
  • Loading branch information
Narretz committed Jan 31, 2018
1 parent 1e9eadc commit 3fc6843
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions scripts/code.angularjs.org-firebase/functions/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ function sendStoredFile(request, response) {
}

if (!fileName) {
//Root
// Root
return getDirectoryListing('/').catch(sendErrorResponse);
}

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

if (path === '/') {
// Let the latest versions appear first
directoryList.reverse();
}

directoryList.forEach(directoryPath => {
const dirName = directoryPath.split('/').reverse()[1];
contentList += `<a href="${dirName}/">${dirName}/</a><br>`;
Expand All @@ -125,11 +130,20 @@ function sendStoredFile(request, response) {
// without trailing slash
const base = request.originalUrl.endsWith('/') ? request.originalUrl : request.originalUrl + '/';

let directoryListing = `
<base href="${base}">
<h1>Index of ${path}</h1>
<hr>
<pre>${contentList}</pre>`;
const directoryListing = `
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1">
<base href="${base}">
</head>
<body>
<h1>Index of ${path}</h1>
<hr>
<pre>${contentList}</pre>
</body>
</html>`;

return response
.status(200)
Expand Down

0 comments on commit 3fc6843

Please sign in to comment.