Skip to content

Commit 49a3ef5

Browse files
committed
feat(builder): Add hierarchical subsection support for API reference sections
Implement support for multi-level section structure in API documentation, allowing sections to contain subsections organized in folder hierarchies. - Sections can now have subsections (e.g., FAQ.md + FAQ/ folder) - Main section content displays as "Overview" subsection - Subsection files automatically loaded from matching directories - Dropdown navigation shows only subsection names, not parent section - The new dynamic sections/subsections are bookmark-able the page automatically scrolls down to the section Example structure: sections/Component/FAQ.md "Overview" subsection sections/Component/FAQ/Example1.md "Example1" subsection sections/Component/FAQ/Example2.md "Example2" subsection JIRA: BGSOFUIPIRIN-6925 Cherry-picked from UI5/openui5@05f6fef35.
1 parent a474700 commit 49a3ef5

File tree

1 file changed

+33
-7
lines changed

1 file changed

+33
-7
lines changed

packages/builder/lib/processors/jsdoc/lib/transformApiJson.js

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1034,15 +1034,41 @@ function transformer(sInputFile, sOutputFile, sLibraryFile, vDependencyAPIFiles,
10341034
const componentDir = path.join(sSectionsDir, sComponentPath);
10351035
if (fs.existsSync(componentDir)) {
10361036
try {
1037+
const dirContents = fs.readdirSync(componentDir, { withFileTypes: true });
1038+
1039+
// Separate files and directories in one pass
1040+
const mdFiles = [];
1041+
const dirNames = new Set();
1042+
dirContents.forEach((dirent) => {
1043+
if (dirent.isFile() && dirent.name.endsWith('.md')) {
1044+
mdFiles.push(dirent.name.replace(/\.md$/, ''));
1045+
} else if (dirent.isDirectory()) {
1046+
dirNames.add(dirent.name);
1047+
}
1048+
});
10371049

1038-
const customSections = fs.readdirSync(componentDir, { withFileTypes: true })
1039-
.filter((dirent) => dirent.isFile() && dirent.name.endsWith('.md'))
1040-
.map((dirent) => dirent.name.replace(/\.md$/, ''));
1041-
1042-
// Store list of available sections for this symbol
1043-
if (customSections.length > 0) {
1044-
symbol.customSections = customSections;
1050+
// Build customSections array with subsection support
1051+
const customSections = mdFiles.map(function(sectionName) {
1052+
// Check if there's a matching directory for this section
1053+
if (dirNames.has(sectionName)) {
1054+
try {
1055+
const subsectionFiles = fs.readdirSync(path.join(componentDir, sectionName), { withFileTypes: true })
1056+
.filter((dirent) => dirent.isFile() && dirent.name.endsWith('.md'))
1057+
.map((dirent) => dirent.name.replace(/\.md$/, ''));
1058+
1059+
if (subsectionFiles.length > 0) {
1060+
return { name: sectionName, hasSubsections: true, subsections: subsectionFiles };
1061+
}
1062+
} catch (error) {
1063+
log.error('Error scanning subsection directory:', path.join(componentDir, sectionName), error);
1064+
}
10451065
}
1066+
return sectionName;
1067+
});
1068+
1069+
if (customSections.length > 0) {
1070+
symbol.customSections = customSections;
1071+
}
10461072

10471073
} catch (error) {
10481074
log.error('Error scanning component sections directory:', componentDir, error);

0 commit comments

Comments
 (0)