Skip to content

Commit 4f64b4e

Browse files
committed
feat: add support for next_steps array in mdx frontmatter
1 parent 35da554 commit 4f64b4e

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

src/components/pageGrid.tsx

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
1+
import path from 'path';
2+
13
import Link from 'next/link';
24

3-
import {nodeForPath} from 'sentry-docs/docTree';
5+
import {DocNode, nodeForPath} from 'sentry-docs/docTree';
46
import {serverContext} from 'sentry-docs/serverContext';
7+
import {isTruthy} from 'sentry-docs/utils';
58

69
type Props = {
710
nextPages: boolean;
@@ -14,21 +17,27 @@ type Props = {
1417
};
1518

1619
export function PageGrid({header}: Props) {
17-
const {rootNode, path} = serverContext();
20+
const {rootNode, path: nodePath} = serverContext();
1821
if (!rootNode) {
1922
return null;
2023
}
2124

22-
const parentNode = nodeForPath(rootNode, path);
25+
const parentNode = nodeForPath(rootNode, nodePath);
2326
if (!parentNode || parentNode.children.length === 0) {
2427
return null;
2528
}
2629

30+
const children: DocNode[] = parentNode.frontmatter.next_steps?.length
31+
? (parentNode.frontmatter.next_steps as string[])
32+
.map(p => nodeForPath(rootNode, path.join(parentNode.path, p)))
33+
.filter(isTruthy) ?? []
34+
: parentNode.children;
35+
2736
return (
2837
<nav>
2938
{header && <h2>{header}</h2>}
3039
<ul>
31-
{parentNode.children
40+
{children
3241
/* NOTE: temp fix while we figure out the reason why some nodes have empty front matter */
3342
.filter(c => c.frontmatter.title)
3443
.map(n => (

src/utils.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,18 @@
11
import type {Transaction} from '@sentry/browser';
22
import qs from 'query-string';
33

4+
/**
5+
* This function is used to filter out any elements that are not truthy and plays nice with TypeScript.
6+
* @param x - The value to check for truthiness.
7+
* @example
8+
* ```typeScript
9+
* let numbers: number[] = [1, undefined, 3, null, 5].filter(isTruthy);
10+
* ```
11+
*/
12+
export const isTruthy = <T>(x?: T): x is Exclude<T, null | undefined> => {
13+
return x !== null && x !== undefined;
14+
};
15+
416
export function sortBy<A>(arr: A[], comp: (v: A) => number): A[] {
517
return arr.sort((a, b) => {
618
const aComp = comp(a);

0 commit comments

Comments
 (0)