Skip to content

Generate a basic directory listing #112

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion _tpl/template.html
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
<html lang="en">
<meta charset="utf-8">
<title>Chrome for Testing availability</title>
<meta content="width=device-width" name="viewport">
<meta name="viewport" content="width=device-width">
<style>
html { font: 1rem/1.6 sans-serif; }
::selection { background: dodgerblue; color: #FFF; }
Expand Down
86 changes: 86 additions & 0 deletions generate-directory-index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import fs from 'node:fs/promises';

import {glob} from 'glob';

import {escapeHtml, minifyHtml} from './html-utils.mjs';

const files = await glob('./*', {
cwd: './dist/',
});

const results = {
digit: [],
json: [],
capOnly: [],
cap: [],
other: [],
};
for (const fileName of files) {
if (/^\d/.test(fileName)) {
results.digit.push(fileName);
continue;
}
if (fileName.endsWith('.json')) {
results.json.push(fileName);
continue;
}
if (/^[A-Z_]+$/.test(fileName)) {
results.capOnly.push(fileName);
continue;
}
if (/^[A-Z]/.test(fileName)) {
results.cap.push(fileName);
continue;
}
results.other.push(fileName);
}

results.digit.sort();
results.json.sort();
results.capOnly.sort();
results.cap.sort();
results.other.sort();

const allFileNames = [
...results.json,
...results.capOnly,
...results.cap,
...results.digit,
...results.other,
];

const html = `
<!DOCTYPE html>
<html lang="en">
<meta charset="utf-8">
<title>Chrome for Testing dashboard + API directory listing</title>
<meta name="viewport" content="width=device-width">
<meta name="robots" content="noindex">
<style>
html { font: 1rem/1.6 sans-serif; }
a { display: block; }
</style>
<ul>
${allFileNames.map(fileName => {
return `<li><a href="${escapeHtml(fileName)}"><code>${escapeHtml(fileName)}</code></a>`;
}).join('\n')}
</ul>
`;
const minified = await minifyHtml(html);
await fs.writeFile('./dist/files.html', minified);
27 changes: 2 additions & 25 deletions generate-html.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,9 @@

import fs from 'node:fs/promises';

import { escape as escapeHtml } from 'lodash-es';
import { minify as minifyHtml } from 'html-minifier-terser';

import {predatesChromeDriverAvailability, predatesChromeHeadlessShellAvailability} from './is-older-version.mjs';
import {readJsonFile} from './json-utils.mjs';
import {escapeHtml, minifyHtml} from './html-utils.mjs';

const OK = '\u2705';
const NOT_OK = '\u274C';
Expand Down Expand Up @@ -152,26 +150,5 @@ const htmlTemplate = await fs.readFile('./_tpl/template.html', 'utf8');
const html = htmlTemplate.toString()
.replace('%%%DATA%%%', render(data))
.replace('%%%TIMESTAMP%%%', data.timestamp);
const minifiedHtml = await minifyHtml(html, {
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: false,
collapseWhitespace: true,
conservativeCollapse: false,
decodeEntities: true,
html5: true,
includeAutoGeneratedTags: false,
minifyCSS: true,
minifyJS: true,
preserveLineBreaks: false,
preventAttributesEscaping: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeEmptyElements: false,
removeOptionalTags: false,
removeRedundantAttributes: true,
removeTagWhitespace: false,
sortAttributes: true,
sortClassName: true,
});
const minifiedHtml = await minifyHtml(html);
await fs.writeFile('./dist/index.html', minifiedHtml);
46 changes: 46 additions & 0 deletions html-utils.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/**
* Copyright 2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the “License”);
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an “AS IS” BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import {minify} from 'html-minifier-terser';
import {escape} from 'lodash-es';

export const minifyHtml = async (html) => {
const minified = await minify(html, {
collapseBooleanAttributes: true,
collapseInlineTagWhitespace: false,
collapseWhitespace: true,
conservativeCollapse: false,
decodeEntities: true,
html5: true,
includeAutoGeneratedTags: false,
minifyCSS: true,
minifyJS: true,
preserveLineBreaks: false,
preventAttributesEscaping: true,
removeAttributeQuotes: true,
removeComments: true,
removeEmptyAttributes: true,
removeEmptyElements: false,
removeOptionalTags: false,
removeRedundantAttributes: true,
removeTagWhitespace: false,
sortAttributes: true,
sortClassName: true,
});
return minified;
};

export const escapeHtml = escape;
4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@
"find": "node --no-warnings find-version.mjs",
"json": "node generate-extra-json.mjs && for id in known-good-versions known-good-versions-with-downloads last-known-good-versions last-known-good-versions-with-downloads latest-patch-versions-per-build latest-patch-versions-per-build-with-downloads latest-versions-per-milestone latest-versions-per-milestone-with-downloads; do jsesc --object --json < \"data/${id}.json\" > \"dist/${id}.json\"; done",
"txt": "node generate-latest-release.mjs",
"render": "node generate-html.mjs && cp logo.svg dist/logo.svg",
"index": "node generate-directory-index.mjs",
"render": "node generate-html.mjs && cp logo.svg dist/logo.svg && node generate-directory-index.mjs",
"build": "npm run find && npm run json && npm run txt && npm run render"
},
"devDependencies": {
"glob": "^10.3.10",
"html-minifier-terser": "7.2.0",
"jsesc": "3.0.2",
"lodash-es": "4.17.21"
Expand Down