-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathgenerate-html-files.js
89 lines (82 loc) · 2.59 KB
/
generate-html-files.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
// SPDX-License-Identifier: MIT-0
import path from 'node:path';
import examplesList from '../examples-list.json' with { type: 'json' };
import { writeFileAsync } from './utils/fsAsync.js';
import config from './config.js';
const frameworkUtils = {
initialMarkup: `<div id="app"></div>`,
getStyles(pageName) {
return `
<link href="vendor.css" rel="stylesheet">
<link href="${pageName}.css" rel="stylesheet">
`;
},
getScripts(pageName) {
return `
<script src="vendor.js"></script>
<script src="${pageName}.js"></script>
`;
},
};
function applyTheme(filename, extension) {
return `${filename}.${extension}`;
}
function getPageContent(pageName, { title }) {
const systemName = 'Cloudscape';
const pageTitle = `${systemName} Demos - ${title}`;
return `<!DOCTYPE html>
<html lang="en">
<head>
<title>${pageTitle}</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
${frameworkUtils.getStyles(pageName)}
</head>
<!-- this class is not needed in production, only for testing -->
<body class="awsui-visual-refresh">
<div id="b">
<header class="custom-main-header" id="h">
<ul class="menu-list awsui-context-top-navigation">
<li class="title"><a href="index.html">Cloudscape Demos</a></li>
</ul>
</header>
${frameworkUtils.initialMarkup}
</div>
<script src="./libs/fake-server.js"></script>
${frameworkUtils.getScripts(pageName)}
</body>
</html>
`;
}
function getIndexContent() {
const links = examplesList
.map(example => `<li><a href="${applyTheme(example.path, 'html')}">${example.title}</a></li>`)
.join('\n');
return `<!DOCTYPE html>
<html lang="en">
<head>
<title>Cloudscape Demos - index</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<ul>${links}</ul>
</body>
</html>
`;
}
function generateIndexFile() {
const filePath = path.join(config.outputPath, 'index.html');
return writeFileAsync(filePath, getIndexContent());
}
function generateHtmlFile(page) {
const pageName = page.path.split('/').pop();
const content = getPageContent(pageName, page);
const filePath = path.join(config.outputPath, applyTheme(pageName, 'html'));
return writeFileAsync(filePath, content);
}
for (const page of examplesList) {
await generateHtmlFile(page);
await generateIndexFile();
}