refactor(guidance): resolve parents from the section index (#17357)

This commit is contained in:
Vincent Koc authored and GitHub committed 2026-12-06 10:31:11 +08:00
1 parent 9088c8d426
commit f092e98c2b
1 file changed
+9 -13
+9 -13
View File
@@ -129,24 +129,20 @@ export const parseGuidanceSections = (
}
const sections: GuideSection[] = [];
for (const { guide, content, headings } of documents) {
const guideSections: GuideSection[] = [];
for (const [ordinal, heading] of headings.entries()) {
const guideStart = sections.length;
for (const { end, ordinal, parent, start, title } of headings) {
// The next heading of any level ends this section's own text: it is
// either the first subsection or the end of the whole section.
const ownEnd = headings[ordinal + 1]?.start ?? heading.end;
const section = {
const ownEnd = headings[ordinal + 1]?.start ?? end;
sections.push({
guide,
ordinal,
heading: heading.title,
content: content.slice(heading.start, heading.end).trim(),
ownContent: content.slice(heading.start, ownEnd).trim(),
heading: title,
content: content.slice(start, end).trim(),
ownContent: content.slice(start, ownEnd).trim(),
parent:
heading.parent === undefined
? undefined
: guideSections[heading.parent],
};
guideSections.push(section);
sections.push(section);
parent === undefined ? undefined : sections[guideStart + parent],
});
}
}
return sections;