Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading