Skip to content

Commit 471fb15

Browse files
authored
Group nav sections per source file, not across all of them (#119)
* Group nav sections per source file, not across all of them Concatenating every navigation block's items before grouping (added to fix comment-induced splits within one file) also merged blocks from different nav: files in antora.yml. A module's real nested section landing right after another module's flat "* *Heading*" bullet got silently absorbed as that heading's child instead of staying its own top-level item, stripping it of promotion. Blocks are now grouped by Math.floor(order), which build-navigation.js sets to the originating file's index, so file boundaries reset section grouping while comment splits within one file still merge as before. Reproduced against docs-playbook (10-module antora.yml with page-tabs-promote-all): the ci module's three sections were being swallowed into docs-restructure's last section (11 children instead of 2), now correctly stay separate, promoted top-level items. * patch version
1 parent 8460c5f commit 471fb15

2 files changed

Lines changed: 37 additions & 15 deletions

File tree

extensions/antora/tabbed-nav/index.js

Lines changed: 36 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -116,20 +116,42 @@ module.exports.register = function ({ config }) {
116116
// every section's landing page individually.
117117
const promoteAll = componentWideAttr('page-tabs-promote-all', asciidoc, playbook.asciidoc) !== undefined
118118

119-
// Antora can split one logical nav list into multiple separate
120-
// "navigation" blocks - not just at module boundaries (separate nav:
121-
// files), but also from a full-line comment inside a single
122-
// content-nav.adoc (e.g. "// * xref:..[]"), which AsciiDoc treats as a
123-
// block break, splitting what the writer sees as one continuous list
124-
// into two independent ones. That severs the "top-level section + its
125-
// flat sibling xrefs" relationship groupFlatNavSections depends on
126-
// before this code ever sees it - a bold heading in one block never
127-
// sees the xrefs that end up in the next, so they're never nested
128-
// under it and never inherit its tab. Concatenating every block's
129-
// items into one flat run before grouping, then putting the result
130-
// back on the first block alone (emptying every other block), makes a
131-
// comment-induced split behave exactly like an unbroken list.
132-
navigation[0].items = groupFlatNavSections([].concat(...navigation.map((n) => n.items)))
119+
// A full-line comment inside a content-nav.adoc (e.g. "// * xref:..[]")
120+
// makes AsciiDoc split what the writer sees as one continuous list into
121+
// two independent "navigation" blocks - severing the "top-level section
122+
// + its flat sibling xrefs" relationship groupFlatNavSections depends
123+
// on: a bold heading in one block never sees the xrefs that end up in
124+
// the next, so they're never nested under it and never inherit its tab.
125+
//
126+
// Separately, when a component's antora.yml lists multiple nav: files
127+
// (one per module), each file's blocks land in this same navigation
128+
// array too. Those genuinely are separate top-level lists and must NOT
129+
// be concatenated together before grouping - doing so lets
130+
// groupFlatNavSections's currentHeader leak from one file into the
131+
// next, silently absorbing another module's whole section as a child
132+
// of the previous module's last section (stripping it of its own
133+
// top-level status, and with it any promotion) whenever that module's
134+
// first top-level item isn't itself a bare "* *Heading*" bullet.
135+
//
136+
// build-navigation.js's buildNavigation gives every nav file's first
137+
// list an integer .order (that file's index in antora.yml's nav:
138+
// list); a comment-induced extra list from the *same* file gets a
139+
// fractional order instead. Flooring .order recovers which file a
140+
// block came from, so blocks are merged only within a file (undoing
141+
// the comment split) and grouped per file (preserving module
142+
// boundaries) before the per-file results are concatenated in file
143+
// order.
144+
const fileGroups = new Map()
145+
for (const nav of navigation) {
146+
const fileIndex = Math.floor(nav.order)
147+
if (!fileGroups.has(fileIndex)) fileGroups.set(fileIndex, [])
148+
fileGroups.get(fileIndex).push(...nav.items)
149+
}
150+
navigation[0].items = [].concat(
151+
...Array.from(fileGroups.keys())
152+
.sort((a, b) => a - b)
153+
.map((fileIndex) => groupFlatNavSections(fileGroups.get(fileIndex)))
154+
)
133155
for (let i = 1; i < navigation.length; i++) navigation[i].items = []
134156

135157
for (const nav of navigation) {

extensions/antora/tabbed-nav/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@neo4j-antora/tabbed-nav",
3-
"version": "0.3.3",
3+
"version": "0.3.4",
44
"description": "Antora extension, Express middleware, S3 aggregator, and turnkey dev server for tabbed cross-docset navigation across Neo4j docs repos.",
55
"main": "index.js",
66
"exports": {

0 commit comments

Comments
 (0)