Skip to content

Commit 8176ce6

Browse files
authored
feat: Add support for next_steps in front matter in PageGrid (#9434)
* fix: don't show next steps if node has no children * feat: add support for `next_steps` array in mdx frontmatter * update pageGrid component docs * fix: remove useless PageGrid laravel/other-versions * improve pageGrid docs * fix: make TS happy * rename isTruthy util to isNotNil
1 parent 0bed01e commit 8176ce6

File tree

11 files changed

+51
-30
lines changed

11 files changed

+51
-30
lines changed

docs/contributing/pages/components.mdx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -195,16 +195,28 @@ See also the [Alert component](#alert).
195195

196196
## PageGrid
197197

198-
Render all child pages of this document, including their `description` if available.
198+
Render all `next_steps` of this document or default child pages, including their `description` if available.
199+
200+
You can specify `next_steps` in the frontmatter of a page to include them in the grid. It supports relative paths and will automatically resolve them.
199201

200202
```markdown {tabTitle:Example}
203+
---
204+
# in the frontmatter of a page:
205+
next_steps:
206+
- ./child-one
207+
- ./child-two
208+
- ../parent/child-three
209+
---
210+
201211
<PageGrid />
202212
```
203213

204214
Attributes:
205215

206216
- `header` (string) - optional header value to include, rendered as an H2
217+
207218
- `nextPages` (boolean) - only render pages which come next based on sidebar ordering
219+
208220
- `exclude` (string[]) - an array of pages to exclude from the grid. Specify the file name of the page, for example, `"index"` for `index.mdx`.
209221

210222
## PlatformContent

docs/platforms/php/guides/laravel/other-versions/laravel4.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -63,5 +63,3 @@ If you wish to wire up Sentry anywhere outside of the standard error handlers, o
6363
```php
6464
$app['sentry']->setRelease(Git::sha());
6565
```
66-
67-
<PageGrid nextPages header="Next Steps" />

docs/platforms/php/guides/laravel/other-versions/laravel5.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,3 @@ You most likely don't want errors to be sent to Sentry when you are developing o
9999
You can also do this by not defining `SENTRY_LARAVEL_DSN` in your `.env` or by defining it as `SENTRY_LARAVEL_DSN=null`.
100100

101101
If you do leave Sentry enabled when developing or running tests, it's possible for it to have a negative effect on the performance of your application or test suite.
102-
103-
<PageGrid nextPages header="Next Steps" />

docs/platforms/php/guides/laravel/other-versions/laravel6-7.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -93,5 +93,3 @@ You most likely don't want errors to be sent to Sentry when you are developing o
9393
You can also do this by not defining `SENTRY_LARAVEL_DSN` in your `.env` or by defining it as `SENTRY_LARAVEL_DSN=null`.
9494

9595
If you do leave Sentry enabled when developing or running tests, it's possible for it to have a negative effect on the performance of your application or test suite.
96-
97-
<PageGrid nextPages header="Next Steps" />

docs/platforms/php/guides/laravel/other-versions/lumen.mdx

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,5 +87,3 @@ You most likely don't want errors to be sent to Sentry when you are developing o
8787
You can also do this by not defining `SENTRY_LARAVEL_DSN` in your `.env` or by defining it as `SENTRY_LARAVEL_DSN=null`.
8888

8989
If you do leave Sentry enabled when developing or running tests, it's possible for it to have a negative effect on the performance of your application or test suite.
90-
91-
<PageGrid nextPages header="Next Steps" />

src/components/docPage/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import {getCurrentGuide, getCurrentPlatform, nodeForPath} from 'sentry-docs/docT
44
import {serverContext} from 'sentry-docs/serverContext';
55
import {FrontMatter} from 'sentry-docs/types';
66
import {PaginationNavNode} from 'sentry-docs/types/paginationNavNode';
7-
import {isTruthy} from 'sentry-docs/utils';
7+
import {isNotNil} from 'sentry-docs/utils';
88
import {getUnversionedPath} from 'sentry-docs/versioning';
99

1010
import './type.scss';
@@ -50,7 +50,7 @@ export function DocPage({
5050

5151
const pathname = serverContext().path.join('/');
5252

53-
const searchPlatforms = [currentPlatform?.name, currentGuide?.name].filter(isTruthy);
53+
const searchPlatforms = [currentPlatform?.name, currentGuide?.name].filter(isNotNil);
5454

5555
const unversionedPath = getUnversionedPath(path, false);
5656

src/components/pageGrid.tsx

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,33 +1,36 @@
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';
5-
import {sortPages} from 'sentry-docs/utils';
7+
import {isNotNil, sortPages} from 'sentry-docs/utils';
68

79
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-
*/
1310
exclude?: string[];
1411
header?: string;
1512
};
1613

1714
export function PageGrid({header, exclude}: Props) {
18-
const {rootNode, path} = serverContext();
15+
const {rootNode, path: nodePath} = serverContext();
1916

20-
const parentNode = nodeForPath(rootNode, path);
21-
if (!parentNode) {
17+
const parentNode = nodeForPath(rootNode, nodePath);
18+
if (!parentNode || parentNode.children.length === 0) {
2219
return null;
2320
}
2421

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+
2528
return (
2629
<nav>
2730
{header && <h2>{header}</h2>}
2831
<ul>
2932
{sortPages(
30-
parentNode.children.filter(
33+
children.filter(
3134
c =>
3235
!c.frontmatter.sidebar_hidden &&
3336
c.frontmatter.title &&

src/components/tableOfContents/index.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import {useEffect, useState} from 'react';
44

5-
import {isTruthy} from 'sentry-docs/utils';
5+
import {isNotNil} from 'sentry-docs/utils';
66

77
import styles from './style.module.scss';
88

@@ -104,7 +104,7 @@ export function TableOfContents() {
104104
isActive: false,
105105
};
106106
})
107-
.filter(isTruthy);
107+
.filter(isNotNil);
108108
setTocItems(tocItems_);
109109
}, []);
110110

src/mdx.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import remarkImageSize from './remark-image-size';
2828
import remarkTocHeadings, {TocNode} from './remark-toc-headings';
2929
import remarkVariables from './remark-variables';
3030
import {FrontMatter, Platform, PlatformConfig} from './types';
31-
import {isTruthy} from './utils';
31+
import {isNotNil} from './utils';
3232
import {isVersioned, VERSION_INDICATOR} from './versioning';
3333

3434
const root = process.cwd();
@@ -145,7 +145,7 @@ export function getDevDocsFrontMatter(): FrontMatter[] {
145145
sourcePath: path.join(folder, fileName),
146146
};
147147
})
148-
.filter(isTruthy);
148+
.filter(isNotNil);
149149
return fmts;
150150
}
151151

src/types/frontmatter.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,16 @@ export interface FrontMatter {
3232
* The next page in the bottom pagination navigation.
3333
*/
3434
nextPage?: PaginationNavNode;
35+
/**
36+
* relative links to use in the "next steps" section of the page grid
37+
* takes precendence over children when present
38+
*/
39+
next_steps?: string[];
3540
/**
3641
* Set this to true to disable indexing (robots, algolia) of this content.
3742
*/
3843
noindex?: boolean;
44+
3945
/**
4046
* Specific guides that this page is not relevant to.
4147
*/

0 commit comments

Comments
 (0)