Skip to content

Commit

Permalink
🐛 Fix generate HTML for deeply nested folders
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaoz-Topsy committed Mar 18, 2023
1 parent 322ad5a commit 36b1fcc
Showing 1 changed file with 15 additions and 13 deletions.
28 changes: 15 additions & 13 deletions buildIndex.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,22 +12,24 @@ async function generateHtml() {

async function generateHtmlForFolder(folder) {
let fileLists = [];
const allFiles = fs.readdirSync(folder, { withFileTypes: true });
for (const dirent of allFiles) {
if (dirent.isDirectory()) {

const allFiles = fs.readdirSync(folder, { withFileTypes: true });
for (const dirent of allFiles) {
if (dirent.isDirectory()) {
fileLists.push(getLink(0, dirent.name));
await generateHtmlForFolder(`./cdnFiles/${dirent.name}`, `./${dirent.name}/`);
await generateHtmlForFolder(`./${folder}/${dirent.name}`, `./${dirent.name}/`);
continue;
}
if (dirent.name[0] == ".") continue;
if (dirent.name[0] == "_") continue;
fileLists.push(getLink(1, dirent.name));
}


if (dirent.name.includes('index.html')) continue;
if (dirent.name[0] == ".") continue;
if (dirent.name[0] == "_") continue;
fileLists.push(getLink(1, dirent.name));
}

fileLists.sort();
let htmlString = `

let htmlString = `
<!DOCTYPE html>
<html>
<head>
Expand All @@ -50,7 +52,7 @@ async function generateHtmlForFolder(folder) {
</body>
</html>
`;
fs.writeFile(`${folder}/index.html`, htmlString, ['utf8'], () => { });
fs.writeFile(`${folder}/index.html`, htmlString, ['utf8'], () => { });
}

function getLink(type, name) {
Expand Down

0 comments on commit 36b1fcc

Please sign in to comment.