-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buildIndex.js
65 lines (51 loc) · 1.33 KB
/
buildIndex.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
const fs = require('fs');
const util = require('util');
const readFile = util.promisify(fs.readFile);
const copyFile = util.promisify(fs.copyFile);
async function generateHtml() {
await copyFile('./CNAME', './cdnFiles/CNAME');
await generateHtmlForFolder('./cdnFiles');
}
async function generateHtmlForFolder(folder) {
let fileLists = [];
const allFiles = fs.readdirSync(folder, { withFileTypes: true });
for (const dirent of allFiles) {
if (dirent.isDirectory()) {
fileLists.push(getLink(0, dirent.name));
await generateHtmlForFolder(`./${folder}/${dirent.name}`, `./${dirent.name}/`);
continue;
}
if (dirent.name.includes('index.html')) continue;
if (dirent.name[0] == ".") continue;
if (dirent.name[0] == "_") continue;
fileLists.push(getLink(1, dirent.name));
}
fileLists.sort();
let htmlString = `
<!DOCTYPE html>
<html>
<head>
<style>
ul li a {
text-decoration: none;
}
</style>
</head>
<body>
<h1>AssistantApps - CDN</h1>
<hr />
<ul>
${fileLists.join('\n\t')}
</ul>
</body>
</html>
`;
fs.writeFile(`${folder}/index.html`, htmlString, ['utf8'], () => { });
}
function getLink(type, name) {
let emoji = '❓';
if (type == 0) emoji = '📁';
if (type == 1) emoji = '📄';
return `<li data-sort="${type}-${name.toLowerCase()}"><a href="./${name}">${emoji} ${name}</a></li>`;
}
generateHtml();