Skip to content

Commit

Permalink
update toc gen for more hierarchy
Browse files Browse the repository at this point in the history
  • Loading branch information
greggman committed Nov 2, 2023
1 parent f54fdba commit e561719
Showing 1 changed file with 30 additions and 9 deletions.
39 changes: 30 additions & 9 deletions build.js
Original file line number Diff line number Diff line change
Expand Up @@ -744,17 +744,38 @@ const Builder = function(outBaseDir, options) {
return `<li><a href="/${link}">${toc}</a></li>`;
}

/*
{
'section1': [
'article1.md',
'article2.md',
],
'section2': [
'article3.md',
{
subSection: [
'article4.md',
],
},
],
},
*/

function makeToc(toc) {
return `${
Object.entries(toc).map(([category, files]) => ` <li>${getLocalizedCategory(category)}</li>
function makeTocImpl(entry) {
if (Array.isArray(entry)) {
return entry.map(makeTocImpl).join('\n');
} else if (typeof entry === 'object') {
return Object.entries(entry).map(([category, subEntry]) => ` <li>${getLocalizedCategory(category)}</li>
<ul>
${Array.isArray(files)
? files.map(tocLink).join('\n')
: makeToc(files)
}
</ul>`
).join('\n')
}`;
${makeTocImpl(subEntry)}
</ul>`).join('\n');
} else {
return tocLink(entry);
}
}

return makeTocImpl(toc);
}

g_langInfo.tocHtml = `<ul>${makeToc(toc)}</ul>`;
Expand Down

0 comments on commit e561719

Please sign in to comment.