Repository navigation
Expand file tree
/
Copy pathpatch-doxygen-html.mjs
More file actions
61 lines (55 loc) · 2.06 KB
/
Copy pathpatch-doxygen-html.mjs
File metadata and controls
61 lines (55 loc) · 2.06 KB
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
#!/usr/bin/env node
import { readdir, readFile, writeFile } from "node:fs/promises";
import path from "node:path";
import { fileURLToPath } from "node:url";
export async function patchDoxygenHtml(root) {
let changed = 0;
let visited = 0;
async function visit(directory) {
for (const entry of await readdir(directory, { withFileTypes: true })) {
const entryPath = path.join(directory, entry.name);
if (entry.isDirectory()) {
await visit(entryPath);
continue;
}
if (!entry.isFile() || !entry.name.endsWith(".html")) continue;
visited += 1;
const source = await readFile(entryPath, "utf8");
let html = source;
if (!/<meta\s+name=["']viewport["']/i.test(html)) {
const withViewport = html.replace(
/(<meta\s+http-equiv="Content-Type"[^>]*>)/i,
'$1\n<meta name="viewport" content="width=device-width, initial-scale=1">',
);
html = withViewport === html
? html.replace(
/(<meta\s+charset=["'][^"']+["']\s*>)/i,
'$1\n<meta name="viewport" content="width=device-width, initial-scale=1">',
)
: withViewport;
}
if (html.includes("codefold.init") && !/src=["']codefolding\.js["']/.test(html)) {
html = html.replace(
/(<link\s+href="stylesheet\.css"[^>]*>)/i,
'$1\n<script type="text/javascript" src="codefolding.js"></script>',
);
}
html = html.replaceAll("http://www.gecode.dev/index.html", "https://www.gecode.dev/");
if (html !== source) {
await writeFile(entryPath, html);
changed += 1;
}
}
}
await visit(path.resolve(root));
return { changed, visited };
}
if (process.argv[1] && path.resolve(process.argv[1]) === fileURLToPath(import.meta.url)) {
const root = process.argv[2];
if (!root) {
console.error("Usage: patch-doxygen-html.mjs <generated-html-directory>");
process.exit(2);
}
const result = await patchDoxygenHtml(root);
console.log(`Patched ${result.changed} of ${result.visited} generated HTML files.`);
}