docs-utils: make reference table of content in alphabetical order (#10084)

This commit is contained in:
Shahed Nasser authored and GitHub committed 2024-11-13 18:10:20 +02:00
1 parent 662b096a46
commit c054f47872
1 file changed
+15 -3
@@ -30,7 +30,11 @@ export default function (theme: MarkdownTheme) {
}) })
function pushGroup(group: ReflectionGroup, md: string[]) { function pushGroup(group: ReflectionGroup, md: string[]) {
const children = group.children.map( const children = group.children
.sort((childA, childB) => {
return childA.name.localeCompare(childB.name)
})
.map(
(child) => (child) =>
`- [${escapeChars(child.name)}](${Handlebars.helpers.relativeURL( `- [${escapeChars(child.name)}](${Handlebars.helpers.relativeURL(
child.url child.url
@@ -44,12 +48,20 @@ export default function (theme: MarkdownTheme) {
md.push(`## Table of contents\n\n`) md.push(`## Table of contents\n\n`)
} }
const headingLevel = hideInPageTOC ? `##` : `###` const headingLevel = hideInPageTOC ? `##` : `###`
this.groups?.forEach((group) => { this.groups
?.sort((groupA, groupB) => {
return groupA.title.localeCompare(groupB.title)
})
.forEach((group) => {
const groupTitle = Object.hasOwn(reflectionGroupRename, group.title) const groupTitle = Object.hasOwn(reflectionGroupRename, group.title)
? reflectionGroupRename[group.title] ? reflectionGroupRename[group.title]
: group.title : group.title
if (group.categories) { if (group.categories) {
group.categories.forEach((category) => { group.categories
.sort((catA, catB) => {
return catA.title.localeCompare(catB.title)
})
.forEach((category) => {
md.push(`${headingLevel} ${category.title} ${groupTitle}\n\n`) md.push(`${headingLevel} ${category.title} ${groupTitle}\n\n`)
pushGroup(category as ReflectionGroup, md) pushGroup(category as ReflectionGroup, md)
md.push("\n") md.push("\n")