mirror of
https://github.com/TheAlgorithms/JavaScript.git
synced 2025-07-06 01:18:23 +08:00
Add build_directory_md
This commit is contained in:
54
.github/workflows/script.js
vendored
54
.github/workflows/script.js
vendored
@ -21,7 +21,6 @@ function good_filepaths(top_dir = ".") {
|
|||||||
} else {
|
} else {
|
||||||
if (file.toLowerCase().endsWith(".js")) {
|
if (file.toLowerCase().endsWith(".js")) {
|
||||||
filepaths.push(path.slice(2));
|
filepaths.push(path.slice(2));
|
||||||
// console.log(filepaths);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -47,14 +46,63 @@ function print_path(old_path, new_path) {
|
|||||||
if (i + 1 > old_parts.len || old_parts[i] != new_part) {
|
if (i + 1 > old_parts.len || old_parts[i] != new_part) {
|
||||||
if (new_part) {
|
if (new_part) {
|
||||||
g_output.push(`${md_prefix(i)} ${new_part.replace('_', ' ')}`);
|
g_output.push(`${md_prefix(i)} ${new_part.replace('_', ' ')}`);
|
||||||
// console.log(`${md_prefix(i)} ${new_part.replace('_', ' ')}`);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return new_path;
|
return new_path;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function build_directory_md(top_dir = ".") {
|
||||||
|
old_path = "";
|
||||||
|
filepaths.sort(function(a, b) {
|
||||||
|
if (a.toLowerCase() < b.toLowerCase()) return -1;
|
||||||
|
if (a.toLowerCase() > b.toLowerCase()) return 1;
|
||||||
|
return 0;
|
||||||
|
});
|
||||||
|
for (let filepath of filepaths) {
|
||||||
|
file = filepath.split(path.sep);
|
||||||
|
if (file.length == 1) {
|
||||||
|
filepath = "";
|
||||||
|
filename = file[0];
|
||||||
|
} else {
|
||||||
|
let total = file.length;
|
||||||
|
filename = file[total - 1];
|
||||||
|
filepath = file.splice(0, total - 1).join(path.sep);
|
||||||
|
}
|
||||||
|
if (filepath != old_path) {
|
||||||
|
old_path = print_path(old_path, filepath);
|
||||||
|
}
|
||||||
|
let indent = 0;
|
||||||
|
for (let i = 0; i < filepath.length; ++i) {
|
||||||
|
if (filepath[i] == path.sep) {
|
||||||
|
++indent;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (filepath) {
|
||||||
|
++indent;
|
||||||
|
}
|
||||||
|
let urls = [URL_BASE, filepath, filename];
|
||||||
|
let url = urls.join("/").replace(" ", "%20");
|
||||||
|
// remove extension from filename
|
||||||
|
filename = filename.split(".")[0];
|
||||||
|
g_output.push(`${md_prefix(indent)} [${filename}](${url})`);
|
||||||
|
}
|
||||||
|
g_output = g_output.join('\n');
|
||||||
|
return g_output;
|
||||||
|
}
|
||||||
|
|
||||||
good_filepaths();
|
good_filepaths();
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
console.log(filepaths);
|
// once the filepaths have been computed
|
||||||
|
build_directory_md();
|
||||||
|
// console.log(filepaths);
|
||||||
|
}, 1000);
|
||||||
|
setTimeout(() => {
|
||||||
|
// once the g_output has been constructed, write to the file
|
||||||
|
fs.writeFile('DIRECTORY.md', g_output + '\n', (err) => {
|
||||||
|
if (err) {
|
||||||
|
console.log(err);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
// console.log(g_output);
|
||||||
}, 1000);
|
}, 1000);
|
Reference in New Issue
Block a user