Skip to content

Commit 663aa57

Browse files
authored
Compare page and node URLs less strictly when choosing between multiple indices (swiftlang#936)
This fixes an issue where the URL path in the index data may additionally have a prefix before the /documentation segment. This change allows the comparison to still work in that scenario where there are multiple top-level trees of data provided in the Index JSON. Resolves: rdar://147829785
1 parent fa2044a commit 663aa57

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/utils/navigatorData.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ function extractRootNode(data) {
193193
//
194194
// otherwise, the first provided node will be used
195195
return data.length === 1 ? data[0] : (data.find(node => (
196-
node.path.toLowerCase() === rootPath.toLowerCase()
196+
node.path.toLowerCase().endsWith(rootPath.toLowerCase())
197197
)) ?? data[0]);
198198
}
199199

tests/unit/utils/navigatorData.spec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -357,6 +357,18 @@ describe('when multiple top-level children are provided', () => {
357357
},
358358
],
359359
};
360+
const b2 = {
361+
type: 'module',
362+
title: 'b',
363+
path: '/some/prefix/documentation/b',
364+
children: [
365+
{
366+
type: 'article',
367+
title: 'b1',
368+
path: '/some/prefix/documentation/b/b1',
369+
},
370+
],
371+
};
360372

361373
describe('flattenNavigationIndex', () => {
362374
it('prefers the root child with the same url path prefix', () => {
@@ -376,6 +388,9 @@ describe('when multiple top-level children are provided', () => {
376388
flattenedIndex = flattenNavigationIndex({ swift: [a, b] });
377389
expect(flattenedIndex.swift.length).toBe(1);
378390
expect(flattenedIndex.swift[0].title).toBe(b.children[0].title);
391+
flattenedIndex = flattenNavigationIndex({ swift: [a, b2] });
392+
expect(flattenedIndex.swift.length).toBe(1);
393+
expect(flattenedIndex.swift[0].title).toBe(b2.children[0].title);
379394

380395
// fallback to first root node when multiple top-level nodes are provided
381396
// and none of them is a "module"
@@ -406,6 +421,8 @@ describe('when multiple top-level children are provided', () => {
406421
// prefers root node with same url path prefix when multiple are provided
407422
props = extractTechnologyProps({ swift: [a, b] });
408423
expect(props.swift.technology).toBe(b.title);
424+
props = extractTechnologyProps({ swift: [a, b2] });
425+
expect(props.swift.technology).toBe(b2.title);
409426

410427
// fallback to first root node when multiple top-level nodes are provided
411428
// and none of them is a "module"

0 commit comments

Comments
 (0)