|
| 1 | +import path from 'path'; |
| 2 | + |
1 | 3 | import Link from 'next/link'; |
2 | 4 |
|
3 | | -import {nodeForPath} from 'sentry-docs/docTree'; |
| 5 | +import {DocNode, nodeForPath} from 'sentry-docs/docTree'; |
4 | 6 | import {serverContext} from 'sentry-docs/serverContext'; |
5 | | -import {sortPages} from 'sentry-docs/utils'; |
| 7 | +import {isNotNil, sortPages} from 'sentry-docs/utils'; |
6 | 8 |
|
7 | 9 | type Props = { |
8 | | - nextPages: boolean; |
9 | | - /** |
10 | | - * A list of pages to exclude from the grid. |
11 | | - * Specify the file name of the page, for example, "index" for "index.mdx" |
12 | | - */ |
13 | 10 | exclude?: string[]; |
14 | 11 | header?: string; |
15 | 12 | }; |
16 | 13 |
|
17 | 14 | export function PageGrid({header, exclude}: Props) { |
18 | | - const {rootNode, path} = serverContext(); |
| 15 | + const {rootNode, path: nodePath} = serverContext(); |
19 | 16 |
|
20 | | - const parentNode = nodeForPath(rootNode, path); |
21 | | - if (!parentNode) { |
| 17 | + const parentNode = nodeForPath(rootNode, nodePath); |
| 18 | + if (!parentNode || parentNode.children.length === 0) { |
22 | 19 | return null; |
23 | 20 | } |
24 | 21 |
|
| 22 | + const children: DocNode[] = parentNode.frontmatter.next_steps?.length |
| 23 | + ? (parentNode.frontmatter.next_steps |
| 24 | + .map(p => nodeForPath(rootNode, path.join(parentNode.path, p))) |
| 25 | + .filter(isNotNil) ?? []) |
| 26 | + : parentNode.children; |
| 27 | + |
25 | 28 | return ( |
26 | 29 | <nav> |
27 | 30 | {header && <h2>{header}</h2>} |
28 | 31 | <ul> |
29 | 32 | {sortPages( |
30 | | - parentNode.children.filter( |
| 33 | + children.filter( |
31 | 34 | c => |
32 | 35 | !c.frontmatter.sidebar_hidden && |
33 | 36 | c.frontmatter.title && |
|
0 commit comments