Skip to content

Commit b971510

Browse files
committed
Add build_directory_md
1 parent 337f3c2 commit b971510

File tree

1 file changed

+51
-3
lines changed

1 file changed

+51
-3
lines changed

.github/workflows/script.js

Lines changed: 51 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ function good_filepaths(top_dir = ".") {
2121
} else {
2222
if (file.toLowerCase().endsWith(".js")) {
2323
filepaths.push(path.slice(2));
24-
// console.log(filepaths);
2524
}
2625
}
2726
});
@@ -47,14 +46,63 @@ function print_path(old_path, new_path) {
4746
if (i + 1 > old_parts.len || old_parts[i] != new_part) {
4847
if (new_part) {
4948
g_output.push(`${md_prefix(i)} ${new_part.replace('_', ' ')}`);
50-
// console.log(`${md_prefix(i)} ${new_part.replace('_', ' ')}`);
5149
}
5250
}
5351
}
5452
return new_path;
5553
}
5654

55+
function build_directory_md(top_dir = ".") {
56+
old_path = "";
57+
filepaths.sort(function(a, b) {
58+
if (a.toLowerCase() < b.toLowerCase()) return -1;
59+
if (a.toLowerCase() > b.toLowerCase()) return 1;
60+
return 0;
61+
});
62+
for (let filepath of filepaths) {
63+
file = filepath.split(path.sep);
64+
if (file.length == 1) {
65+
filepath = "";
66+
filename = file[0];
67+
} else {
68+
let total = file.length;
69+
filename = file[total - 1];
70+
filepath = file.splice(0, total - 1).join(path.sep);
71+
}
72+
if (filepath != old_path) {
73+
old_path = print_path(old_path, filepath);
74+
}
75+
let indent = 0;
76+
for (let i = 0; i < filepath.length; ++i) {
77+
if (filepath[i] == path.sep) {
78+
++indent;
79+
}
80+
}
81+
if (filepath) {
82+
++indent;
83+
}
84+
let urls = [URL_BASE, filepath, filename];
85+
let url = urls.join("/").replace(" ", "%20");
86+
// remove extension from filename
87+
filename = filename.split(".")[0];
88+
g_output.push(`${md_prefix(indent)} [${filename}](${url})`);
89+
}
90+
g_output = g_output.join('\n');
91+
return g_output;
92+
}
93+
5794
good_filepaths();
5895
setTimeout(() => {
59-
console.log(filepaths);
96+
// once the filepaths have been computed
97+
build_directory_md();
98+
// console.log(filepaths);
99+
}, 1000);
100+
setTimeout(() => {
101+
// once the g_output has been constructed, write to the file
102+
fs.writeFile('DIRECTORY.md', g_output + '\n', (err) => {
103+
if (err) {
104+
console.log(err);
105+
}
106+
})
107+
// console.log(g_output);
60108
}, 1000);

0 commit comments

Comments
 (0)