Skip to content
Merged
Show file tree
Hide file tree
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
16 changes: 16 additions & 0 deletions changelog-toc.js
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,21 @@
activeId = null;
}

function normalizeNavigationHeadings() {
// Hosted Mintlify adds navigation headings that older local previews omit.
document.querySelectorAll('[data-agent-docs-index] h2, #table-of-contents h2, #navigation-items h5').forEach(function (heading) {
var label = document.createElement("div");
Array.from(heading.attributes).forEach(function (attribute) {
if (attribute.name !== "role" && attribute.name !== "aria-level") {
label.setAttribute(attribute.name, attribute.value);
}
});
// Move the button itself so its click handler and aria-labelledby survive.
while (heading.firstChild) label.appendChild(heading.firstChild);
heading.replaceWith(label);
});
}

function setupHeadingLinks() {
var nativeLink = document.querySelectorAll('#content .group a.group\\/link')[0];
if (!nativeLink) return;
Expand Down Expand Up @@ -410,6 +425,7 @@
}

redirectHistoricalAnchor();
normalizeNavigationHeadings();
setupLazyVideos();
setupHeadingLinks();
setupMonthReader();
Expand Down
33 changes: 33 additions & 0 deletions scripts/test_changelog_navigation.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,36 @@ test('sidebar selection follows reading forward and backward without scrolling t
assert.equal(october.attributes['aria-current'], 'location');
assert.equal(september.attributes['aria-current'], undefined);
});

test('hosted navigation labels stop being headings without replacing their interactive children', () => {
const button = { text: 'On this page', clickHandler: () => true };
const labels = [
{ attributes: [], children: [{text: 'Documentation Index'}] },
{ attributes: [{name: 'id', value: 'toc-label'}, {name: 'class', value: 'm-0 font-normal'}], children: [button] },
].map(node => ({ ...node,
get firstChild() { return this.children[0]; },
replaceWith(replacement) { this.replacement = replacement; },
}));
const document = {
documentElement: { setAttribute() {} },
querySelectorAll(selector) { return selector.startsWith('[data-agent-docs-index]') ? labels.filter(x => !x.replacement) : []; },
createElement(tag) { return { tag, attributes: {}, children: [],
setAttribute(k,v) { this.attributes[k] = v; },
appendChild(child) {
const owner = labels.find(x => x.children.includes(child));
owner.children.splice(owner.children.indexOf(child), 1);
this.children.push(child);
},
}; },
};
const window = {addEventListener() {}};
const exposed = source.replace(' collectPairs();\n})();', ' window.normalize = normalizeNavigationHeadings;\n})();');
vm.runInNewContext(exposed, {document, window, MutationObserver: class {observe() {}}});
window.normalize();
window.normalize();
assert.equal(labels[0].replacement.tag, 'div');
assert.equal(labels[1].replacement.attributes.id, 'toc-label');
assert.equal(labels[1].replacement.attributes.class, 'm-0 font-normal');
assert.equal(labels[1].replacement.children[0], button);
assert.equal(button.clickHandler(), true);
});
Loading