forked from anusarati/strprox
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgen_links.ts
More file actions
45 lines (31 loc) · 1.15 KB
/
gen_links.ts
File metadata and controls
45 lines (31 loc) · 1.15 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
let web_root = "https://ple1n.github.io/strprox/"
async function findIndexHtmlFiles(dir: string): Promise<string[]> {
const results: string[] = [];
async function traverseDirectory(currentDir: string) {
for await (const entry of Deno.readDir(currentDir)) {
const fullPath = `${currentDir}/${entry.name}`;
if (entry.isDirectory) {
await traverseDirectory(fullPath); // Recurse into subdirectory
} else if (entry.isFile && entry.name === "index.html") {
results.push(fullPath); // Store the path of index.html
}
}
}
await traverseDirectory(dir);
return results;
}
const dirPath = "./docs";
let paths = await findIndexHtmlFiles(dirPath);
paths = paths.map(x => x.replace("./docs/", web_root));
console.log(paths);
const filePath = "README.md";
const fileContent = await Deno.readTextFile(filePath);
let index = "";
for (let p of paths) {
index += `- ${p}\n`
}
const updatedContent = fileContent.replace(
/## Benchmark reports[\s\S]*?(?=\n##|$)/,
`## Benchmark reports\n\n${index}`
);
await Deno.writeTextFile(filePath, updatedContent);