Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion docs/contributing/pages/components.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -195,16 +195,28 @@ See also the [Alert component](#alert).

## PageGrid

Render all child pages of this document, including their `description` if available.
Render all `next_steps` of this document or default child pages, including their `description` if available.

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.

```markdown {tabTitle:Example}
---
# in the frontmatter of a page:
next_steps:
- ./child-one
- ./child-two
- ../parent/child-three
---

<PageGrid />
```

Attributes:

- `header` (string) - optional header value to include, rendered as an H2

- `nextPages` (boolean) - only render pages which come next based on sidebar ordering

- `exclude` (string[]) - an array of pages to exclude from the grid. Specify the file name of the page, for example, `"index"` for `index.mdx`.

## PlatformContent
Expand Down
2 changes: 0 additions & 2 deletions docs/platforms/php/guides/laravel/other-versions/laravel4.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -63,5 +63,3 @@ If you wish to wire up Sentry anywhere outside of the standard error handlers, o
```php
$app['sentry']->setRelease(Git::sha());
```

<PageGrid nextPages header="Next Steps" />
2 changes: 0 additions & 2 deletions docs/platforms/php/guides/laravel/other-versions/laravel5.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -99,5 +99,3 @@ You most likely don't want errors to be sent to Sentry when you are developing o
You can also do this by not defining `SENTRY_LARAVEL_DSN` in your `.env` or by defining it as `SENTRY_LARAVEL_DSN=null`.

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.

<PageGrid nextPages header="Next Steps" />
Original file line number Diff line number Diff line change
Expand Up @@ -93,5 +93,3 @@ You most likely don't want errors to be sent to Sentry when you are developing o
You can also do this by not defining `SENTRY_LARAVEL_DSN` in your `.env` or by defining it as `SENTRY_LARAVEL_DSN=null`.

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.

<PageGrid nextPages header="Next Steps" />
2 changes: 0 additions & 2 deletions docs/platforms/php/guides/laravel/other-versions/lumen.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -87,5 +87,3 @@ You most likely don't want errors to be sent to Sentry when you are developing o
You can also do this by not defining `SENTRY_LARAVEL_DSN` in your `.env` or by defining it as `SENTRY_LARAVEL_DSN=null`.

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.

<PageGrid nextPages header="Next Steps" />
4 changes: 2 additions & 2 deletions src/components/docPage/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import {getCurrentGuide, getCurrentPlatform, nodeForPath} from 'sentry-docs/docT
import {serverContext} from 'sentry-docs/serverContext';
import {FrontMatter} from 'sentry-docs/types';
import {PaginationNavNode} from 'sentry-docs/types/paginationNavNode';
import {isTruthy} from 'sentry-docs/utils';
import {isNotNil} from 'sentry-docs/utils';
import {getUnversionedPath} from 'sentry-docs/versioning';

import './type.scss';
Expand Down Expand Up @@ -50,7 +50,7 @@ export function DocPage({

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

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

const unversionedPath = getUnversionedPath(path, false);

Expand Down
25 changes: 14 additions & 11 deletions src/components/pageGrid.tsx
Original file line number Diff line number Diff line change
@@ -1,33 +1,36 @@
import path from 'path';

import Link from 'next/link';

import {nodeForPath} from 'sentry-docs/docTree';
import {DocNode, nodeForPath} from 'sentry-docs/docTree';
import {serverContext} from 'sentry-docs/serverContext';
import {sortPages} from 'sentry-docs/utils';
import {isNotNil, sortPages} from 'sentry-docs/utils';

type Props = {
nextPages: boolean;
/**
* A list of pages to exclude from the grid.
* Specify the file name of the page, for example, "index" for "index.mdx"
*/
exclude?: string[];
header?: string;
};

export function PageGrid({header, exclude}: Props) {
const {rootNode, path} = serverContext();
const {rootNode, path: nodePath} = serverContext();

const parentNode = nodeForPath(rootNode, path);
if (!parentNode) {
const parentNode = nodeForPath(rootNode, nodePath);
if (!parentNode || parentNode.children.length === 0) {
return null;
}

const children: DocNode[] = parentNode.frontmatter.next_steps?.length
? (parentNode.frontmatter.next_steps
.map(p => nodeForPath(rootNode, path.join(parentNode.path, p)))
.filter(isNotNil) ?? [])
: parentNode.children;

return (
<nav>
{header && <h2>{header}</h2>}
<ul>
{sortPages(
parentNode.children.filter(
children.filter(
c =>
!c.frontmatter.sidebar_hidden &&
c.frontmatter.title &&
Expand Down
4 changes: 2 additions & 2 deletions src/components/tableOfContents/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import {useEffect, useState} from 'react';

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

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

Expand Down Expand Up @@ -104,7 +104,7 @@ export function TableOfContents() {
isActive: false,
};
})
.filter(isTruthy);
.filter(isNotNil);
setTocItems(tocItems_);
}, []);

Expand Down
4 changes: 2 additions & 2 deletions src/mdx.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import remarkImageSize from './remark-image-size';
import remarkTocHeadings, {TocNode} from './remark-toc-headings';
import remarkVariables from './remark-variables';
import {FrontMatter, Platform, PlatformConfig} from './types';
import {isTruthy} from './utils';
import {isNotNil} from './utils';
import {isVersioned, VERSION_INDICATOR} from './versioning';

const root = process.cwd();
Expand Down Expand Up @@ -145,7 +145,7 @@ export function getDevDocsFrontMatter(): FrontMatter[] {
sourcePath: path.join(folder, fileName),
};
})
.filter(isTruthy);
.filter(isNotNil);
return fmts;
}

Expand Down
6 changes: 6 additions & 0 deletions src/types/frontmatter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,16 @@ export interface FrontMatter {
* The next page in the bottom pagination navigation.
*/
nextPage?: PaginationNavNode;
/**
* relative links to use in the "next steps" section of the page grid
* takes precendence over children when present
*/
next_steps?: string[];
/**
* Set this to true to disable indexing (robots, algolia) of this content.
*/
noindex?: boolean;

/**
* Specific guides that this page is not relevant to.
*/
Expand Down
16 changes: 12 additions & 4 deletions src/utils.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
import qs from 'query-string';

/**
* This function is used to filter out any elements that are not truthy and plays nice with TypeScript.
* @param x - The value to check for truthiness.
* @example
* ```typeScript
* let numbers: number[] = [1, undefined, 3, null, 5].filter(isTruthy);
* ```
*/
export const isNotNil = <T>(x?: T): x is Exclude<T, null | undefined> => {
return x !== null && x !== undefined;
};

export function sortBy<A>(arr: A[], comp: (v: A) => number): A[] {
return arr.sort((a, b) => {
const aComp = comp(a);
Expand Down Expand Up @@ -89,10 +101,6 @@ export function captureException(exception: unknown): void {
}
}

export function isTruthy<T>(value: T | undefined | null): value is T {
return value !== undefined && value !== null;
}

export const isLocalStorageAvailable = () => typeof localStorage !== 'undefined';

export const stripTrailingSlash = (url: string) => {
Expand Down
Loading