-
Notifications
You must be signed in to change notification settings - Fork 0
/
mkindex.js
executable file
·51 lines (41 loc) · 1.02 KB
/
mkindex.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
#!/usr/bin/env node
const fs = require('fs');
const BASEURL = 'https://mellonscholarlycommunication.github.io/service_node/';
const dir = process.argv[2];
if (!dir) {
console.log('usage: mkindex.js dir');
process.exit(1);
}
mkIndex(dir);
function mkIndex(dir) {
const ls = fs.readdirSync(dir);
const parts = [];
for (let i = 0 ; i < ls.length ; i++) {
const path = `${dir}/${ls[i]}`;
if (fs.lstatSync(path).isDirectory()) {
mkIndex(path);
}
parts.push(path);
}
const sdir = dir.replaceAll(/.*\//g,'');
let html = `
<html>
<head>
<link rel="stylesheet" href="https://unpkg.com/mvp.css">
</head>
<body>
<h1>${sdir}</h1>
<ul>
`;
parts.forEach( (part) => {
const spart = part.replaceAll(/.*\//g,'');
html += `<li><a href="${BASEURL}${part}">${spart}</a></li>\n`;
});
html += `
</ul>
</body>
</html>
`;
console.log(`writing ${dir}/index.html`);
fs.writeFileSync(`${dir}/index.html`,html);
}