-
Notifications
You must be signed in to change notification settings - Fork 294
Expand file tree
/
Copy pathpage.jsx
More file actions
133 lines (109 loc) · 4.04 KB
/
page.jsx
File metadata and controls
133 lines (109 loc) · 4.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
/* eslint-disable react/prop-types */
import { notFound } from 'next/navigation';
import Post from 'components/pages/doc/post';
import VERCEL_URL from 'constants/base';
import { DOCS_DIR_PATH, CHANGELOG_DIR_PATH, isUnusedOrSharedContent } from 'constants/content';
import LINKS from 'constants/links';
import { getPostBySlug } from 'utils/api-content';
import { getAllPosts, getAllChangelogs, getNavigationLinks, getNavigation } from 'utils/api-docs';
import { getBreadcrumbs } from 'utils/get-breadcrumbs';
import { getFlatSidebar } from 'utils/get-flat-sidebar';
import getMetadata from 'utils/get-metadata';
import getTableOfContents from 'utils/get-table-of-contents';
export async function generateStaticParams() {
const posts = await getAllPosts();
if (!posts) return notFound();
return posts.map(({ slug }) => {
const slugsArray = slug.split('/');
return {
slug: slugsArray,
};
});
}
export async function generateMetadata(props) {
const params = await props.params;
const { slug } = params;
const currentSlug = slug.join('/');
if (isUnusedOrSharedContent(currentSlug)) return notFound();
const post = getPostBySlug(currentSlug, DOCS_DIR_PATH);
const isChangelog = currentSlug === 'changelog';
if (!isChangelog && !post) return notFound();
const title = post?.data?.title || 'Changelog';
const encodedTitle = Buffer.from(title).toString('base64');
const sidebar = getNavigation();
const flatSidebar = await getFlatSidebar(sidebar);
const breadcrumbs = getBreadcrumbs(currentSlug, flatSidebar);
const category = breadcrumbs.length > 0 ? breadcrumbs[0].title : '';
const encodedCategory = category && Buffer.from(category).toString('base64');
return getMetadata({
title: `${title} - Neon Docs`,
description: isChangelog ? 'The latest product updates from Neon' : post.excerpt,
imagePath: `${VERCEL_URL}/docs/og?title=${encodedTitle}&category=${encodedCategory}`,
pathname: `${LINKS.docs}/${currentSlug}`,
rssPathname: isChangelog ? `${LINKS.changelog}/rss.xml` : null,
robotsNoindex: post?.data?.noindex ? 'noindex' : null,
type: 'article',
markdownPath: `/docs/${currentSlug}.md`,
});
}
const DocPost = async (props) => {
const params = await props.params;
const { slug } = params;
const currentSlug = slug.join('/');
if (isUnusedOrSharedContent(currentSlug)) return notFound();
const sidebar = getNavigation();
const flatSidebar = await getFlatSidebar(sidebar);
const isDocsIndex = currentSlug === 'introduction';
const isChangelogIndex = currentSlug === 'changelog' || currentSlug.startsWith('changelog/');
const allChangelogPosts = await getAllChangelogs();
const breadcrumbs = getBreadcrumbs(currentSlug, flatSidebar);
const navigationLinks = getNavigationLinks(currentSlug, flatSidebar);
const gitHubPath = isChangelogIndex ? CHANGELOG_DIR_PATH : `${DOCS_DIR_PATH}/${currentSlug}.md`;
const post = getPostBySlug(currentSlug, DOCS_DIR_PATH);
if (!isChangelogIndex && !post) return notFound();
if (isChangelogIndex) {
return (
<Post
data={{}}
content={{}}
breadcrumbs={breadcrumbs}
currentSlug={currentSlug}
gitHubPath={gitHubPath}
changelogPosts={allChangelogPosts}
navigationLinks={navigationLinks}
changelogActiveLabel="all"
isChangelog
/>
);
}
const { data, content } = post;
const tableOfContents = getTableOfContents(content);
const jsonLd = {
'@context': 'https://schema.org',
'@type': 'Article',
headline: data.title,
author: {
'@type': 'Organization',
name: 'Neon',
},
};
return (
<>
<script
type="application/ld+json"
dangerouslySetInnerHTML={{ __html: JSON.stringify(jsonLd) }}
/>
<Post
content={content}
data={data}
breadcrumbs={breadcrumbs}
navigationLinks={navigationLinks}
currentSlug={currentSlug}
gitHubPath={gitHubPath}
tableOfContents={tableOfContents}
isDocsIndex={isDocsIndex}
/>
</>
);
};
export default DocPost;