Skip to content

Commit

Permalink
docs-utils: make reference table of content in alphabetical order (#1…
Browse files Browse the repository at this point in the history
  • Loading branch information
shahednasser authored Nov 13, 2024
1 parent 662b096 commit c054f47
Showing 1 changed file with 36 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,16 @@ export default function (theme: MarkdownTheme) {
})

function pushGroup(group: ReflectionGroup, md: string[]) {
const children = group.children.map(
(child) =>
`- [${escapeChars(child.name)}](${Handlebars.helpers.relativeURL(
child.url
)})`
)
const children = group.children
.sort((childA, childB) => {
return childA.name.localeCompare(childB.name)
})
.map(
(child) =>
`- [${escapeChars(child.name)}](${Handlebars.helpers.relativeURL(
child.url
)})`
)
md.push(children.join("\n"))
}

Expand All @@ -44,26 +48,34 @@ export default function (theme: MarkdownTheme) {
md.push(`## Table of contents\n\n`)
}
const headingLevel = hideInPageTOC ? `##` : `###`
this.groups?.forEach((group) => {
const groupTitle = Object.hasOwn(reflectionGroupRename, group.title)
? reflectionGroupRename[group.title]
: group.title
if (group.categories) {
group.categories.forEach((category) => {
md.push(`${headingLevel} ${category.title} ${groupTitle}\n\n`)
pushGroup(category as ReflectionGroup, md)
md.push("\n")
})
} else {
if (!hideInPageTOC || isVisible) {
if (!hideTocHeaders) {
md.push(`${headingLevel} ${groupTitle}\n\n`)
this.groups
?.sort((groupA, groupB) => {
return groupA.title.localeCompare(groupB.title)
})
.forEach((group) => {
const groupTitle = Object.hasOwn(reflectionGroupRename, group.title)
? reflectionGroupRename[group.title]
: group.title
if (group.categories) {
group.categories
.sort((catA, catB) => {
return catA.title.localeCompare(catB.title)
})
.forEach((category) => {
md.push(`${headingLevel} ${category.title} ${groupTitle}\n\n`)
pushGroup(category as ReflectionGroup, md)
md.push("\n")
})
} else {
if (!hideInPageTOC || isVisible) {
if (!hideTocHeaders) {
md.push(`${headingLevel} ${groupTitle}\n\n`)
}
pushGroup(group, md)
md.push("\n")
}
pushGroup(group, md)
md.push("\n")
}
}
})
})
}
return md.length > 0 ? md.join("\n") : null
}
Expand Down

0 comments on commit c054f47

Please sign in to comment.