Skip to content

Commit 83b2029

Browse files
committed
allow overriding pagination through frontmatter
1 parent cd95fbd commit 83b2029

File tree

2 files changed

+37
-9
lines changed

2 files changed

+37
-9
lines changed

app/[[...path]]/page.tsx

Lines changed: 21 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -101,21 +101,34 @@ export default async function Page({params}: {params: {path?: string[]}}) {
101101
}
102102

103103
const pageNode = nodeForPath(rootNode, params.path);
104-
const nextNode = pageNode ? getNextNode(pageNode) : undefined;
105-
const previousNode = pageNode ? getPreviousNode(pageNode) : undefined;
106-
const nextPage = nextNode
107-
? {path: nextNode.path, title: nextNode.frontmatter.title}
108-
: undefined;
109-
const previousPage = previousNode
110-
? {path: previousNode.path, title: previousNode.frontmatter.title}
111-
: undefined;
112104

113105
if (!pageNode) {
114106
// eslint-disable-next-line no-console
115107
console.warn('no page node', params.path);
116108
return notFound();
117109
}
118110

111+
// gather previous and next page that will be displayed in the bottom pagination
112+
let previousPage = pageNode?.frontmatter?.previousPage;
113+
let nextPage = pageNode?.frontmatter?.nextPage;
114+
115+
if (!nextPage || !('path' in nextPage) || !('title' in nextPage)) {
116+
const nextNode = pageNode ? getNextNode(pageNode) : undefined;
117+
nextPage = nextNode
118+
? {path: nextNode.path, title: nextNode.frontmatter.title}
119+
: undefined;
120+
}
121+
122+
if (!previousPage || !('path' in previousPage) || !('title' in previousPage)) {
123+
const previousNode = pageNode ? getPreviousNode(pageNode) : undefined;
124+
previousPage =
125+
previousNode === 'root'
126+
? {path: '', title: 'Welcome to Sentry'}
127+
: previousNode
128+
? {path: previousNode.path, title: previousNode.frontmatter.title}
129+
: undefined;
130+
}
131+
119132
// get the MDX for the current doc and render it
120133
let doc: Awaited<ReturnType<typeof getFileBySlug>> | null = null;
121134
try {

src/types/frontmatter.ts

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import {PaginationNavNode} from './paginationNavNode';
2+
13
/**
24
** a YAML-formatted blob defined at the top of every markdown or mdx file
35
*/
@@ -23,6 +25,11 @@ export interface FrontMatter {
2325
* A list of keywords for indexing with search.
2426
*/
2527
keywords?: string[];
28+
29+
/**
30+
* The next page in the bottom pagination navigation.
31+
*/
32+
nextPage?: PaginationNavNode;
2633
/**
2734
* Set this to true to disable indexing (robots, algolia) of this content.
2835
*/
@@ -31,11 +38,20 @@ export interface FrontMatter {
3138
* Specific guides that this page is not relevant to.
3239
*/
3340
notSupported?: string[];
41+
3442
/**
3543
* Set this to true to disable page-level table of contents rendering.
3644
*/
3745
notoc?: boolean;
3846

47+
/**
48+
* The previous page in the bottom pagination navigation.
49+
*/
50+
previousPage?: PaginationNavNode;
51+
52+
/**
53+
* The next page in the sidebar navigation.
54+
*/
3955
/**
4056
* Set this to true to hide from the sidebar
4157
*/
@@ -60,7 +76,6 @@ export interface FrontMatter {
6076
* Specific guides that this page is relevant to.
6177
*/
6278
supported?: string[];
63-
6479
/**
6580
* Available versions for this page
6681
* @example ['v7.119.0', 'next']

0 commit comments

Comments
 (0)