Skip to content

Commit cd95fbd

Browse files
committed
show welcome page as previous page for root pages
1 parent 6f73a58 commit cd95fbd

File tree

2 files changed

+8
-7
lines changed

2 files changed

+8
-7
lines changed

src/docTree.spec.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ describe('docTree', () => {
270270
expect(getPreviousNode(xA)).toBe(xB);
271271
});
272272

273-
test('should not return siblings for root platform or guide paths', () => {
273+
test('should return root as previous page for root platform or guide paths', () => {
274274
const platforms = createNode('platforms', 'Platforms');
275275
const js = createNode('platforms/javascript', 'JavaScript');
276276
const python = createNode('platforms/python', 'Python');
@@ -286,10 +286,10 @@ describe('docTree', () => {
286286
child.parent = js;
287287
});
288288

289-
expect(getPreviousNode(js)).toBe(undefined);
290-
expect(getPreviousNode(python)).toBe(undefined);
291-
expect(getPreviousNode(nextjs)).toBe(undefined);
292-
expect(getPreviousNode(angular)).toBe(undefined);
289+
expect(getPreviousNode(js)).toBe('root');
290+
expect(getPreviousNode(python)).toBe('root');
291+
expect(getPreviousNode(nextjs)).toBe('root');
292+
expect(getPreviousNode(angular)).toBe('root');
293293
});
294294

295295
test('should not return /platforms as previous page', () => {

src/docTree.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,10 @@ export const getNextNode = (node: DocNode): DocNode | undefined => {
185185
* Returns the previous node in the tree, which is either the last child of the parent,
186186
* the previous sibling, or the previous sibling of a parent node.
187187
*/
188-
export const getPreviousNode = (node: DocNode): DocNode | undefined => {
188+
export const getPreviousNode = (node: DocNode): DocNode | undefined | 'root' => {
189+
// in this special case, calculating the root node is unnecessary so we return a string instead
189190
if (isRootPlatformPath(node.path) || isRootGuidePath(node.path)) {
190-
return undefined;
191+
return 'root';
191192
}
192193

193194
const previousSibling = getPreviousSiblingNode(node);

0 commit comments

Comments
 (0)