docs: add prepare script to generate sidebar (#11894)

This commit is contained in:
Shahed Nasser
2025-03-18 17:37:51 +02:00
committed by GitHub
parent eb2aa8da3c
commit 9ead47c51e
72 changed files with 1709 additions and 295 deletions
+16 -3
View File
@@ -8,14 +8,27 @@ export function findMetadataTitle(content: string): string | undefined {
return headingMatch?.groups?.title
}
const HEADING_REGEX = /# (?<title>.*)/
export function findPageHeading(content: string): string | undefined {
const headingMatch = HEADING_REGEX.exec(content)
const headingMatch = /# (?<title>.*)/.exec(content)
return headingMatch?.groups?.title
}
export function findAllPageHeadings({
content,
level = 1,
}: {
content: string
level?: number
}): string[] {
const regex = new RegExp(
`^${"#".repeat(level)}(?!#) (?<title>.*?)(?:\n|$)`,
"gm"
)
const matches = [...content.matchAll(regex)]
return matches.map((match) => match.groups?.title).filter(Boolean) as string[]
}
export function findPageTitle(filePath: string): string | undefined {
const content = readFileSync(filePath, "utf-8")