-
Notifications
You must be signed in to change notification settings - Fork 808
/
Copy pathpage.tsx
205 lines (184 loc) · 5.67 KB
/
page.tsx
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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
import '@/styles/mdx.css';
import Link from 'next/link';
import { notFound } from 'next/navigation';
import { cn } from '@udecode/cn';
import { allDocs } from 'contentlayer/generated';
import { ChevronRight, ExternalLinkIcon } from 'lucide-react';
import Balancer from 'react-wrap-balancer';
// import { formatBytes, getPackageData } from '@/lib/bundlephobia';
import { getTableOfContents } from '@/lib/toc';
import { PackageInfoType } from '@/hooks/use-package-info';
import { badgeVariants } from '@/components/ui/badge';
import { ScrollArea } from '@/components/ui/scroll-area';
import { Mdx } from '@/components/mdx-components';
import { DocsPager } from '@/components/pager';
import { DashboardTableOfContents } from '@/components/toc';
interface DocPageProps {
params: {
slug: string[];
};
}
function getDocFromParams({ params }: DocPageProps) {
const slug = params.slug?.join('/') || '';
const doc = allDocs.find((_doc) => _doc.slugAsParams === slug);
if (!doc) {
return null;
}
return doc;
}
// export async function generateMetadata({
// params,
// }: DocPageProps): Promise<Metadata> {
// const doc = getDocFromParams({ params });
//
// if (!doc) {
// return {};
// }
//
// return {
// title: doc.title,
// description: doc.description,
// openGraph: {
// title: doc.title,
// description: doc.description,
// type: 'article',
// url: absoluteUrl(doc.slug),
// images: [
// {
// url: siteConfig.ogImage,
// width: 1200,
// height: 630,
// alt: siteConfig.name,
// },
// ],
// },
// twitter: {
// card: 'summary_large_image',
// title: doc.title,
// description: doc.description,
// images: [siteConfig.ogImage],
// creator: '@shadcn',
// },
// };
// }
export async function generateStaticParams(): Promise<
DocPageProps['params'][]
> {
const docs = allDocs.map((doc) => ({
slug: doc.slugAsParams.split('/'),
}));
return docs;
}
export default async function DocPage({ params }: DocPageProps) {
const name = params.slug?.[0];
const isUI = name === 'components';
const doc = getDocFromParams({ params });
const packageInfo: PackageInfoType = {
gzip: '',
name: '',
npm: '',
source: '',
};
// const pkg = docToPackage(name);
// if (pkg) {
// const { gzip: gzipNumber } = await getPackageData(pkg.name);
// const gzip =
// typeof gzipNumber === 'number' ? formatBytes(gzipNumber) : null;
//
// packageInfo.name = pkg.name;
// if (gzip) {
// packageInfo.gzip = gzip;
// }
// packageInfo.source =
// 'https://github.com/udecode/plate/tree/main/packages/' +
// pkg.sourcePath +
// '/src';
// packageInfo.npm = 'https://www.npmjs.com/package/@udecode/' + pkg.name;
// }
if (!doc) {
notFound();
}
// let toc: TableOfContents;
// if (params.slug?.[0] === 'api') {
// toc = getAPITableOfContents(doc.body.raw);
// } else {
// }
const toc = await getTableOfContents(doc.body.raw);
return (
<main className="relative py-6 lg:gap-10 lg:py-8 xl:grid xl:grid-cols-[1fr_300px]">
<div className="mx-auto w-full min-w-0">
<div className="mb-4 flex items-center space-x-1 text-sm text-muted-foreground">
<div className="truncate">{isUI ? 'Components' : 'Docs'}</div>
<ChevronRight className="size-4" />
<div className="font-medium text-foreground">{doc.title}</div>
</div>
<div className="space-y-2">
<h1 className={cn('scroll-m-20 text-4xl font-bold tracking-tight')}>
{doc.title}
</h1>
{doc.description && (
<p className="text-lg text-muted-foreground">
<Balancer>{doc.description}</Balancer>
</p>
)}
</div>
{doc.links || doc.docs ? (
<div className="flex flex-wrap items-center gap-1 pt-4">
{doc.links?.doc && (
<Link
href={doc.links.doc}
target="_blank"
rel="noreferrer"
className={cn(badgeVariants({ variant: 'secondary' }), 'gap-1')}
>
Docs
<ExternalLinkIcon className="size-3" />
</Link>
)}
{doc.links?.api && (
<Link
href={doc.links.api}
target="_blank"
rel="noreferrer"
className={cn(badgeVariants({ variant: 'secondary' }), 'gap-1')}
>
API Reference
<ExternalLinkIcon className="size-3" />
</Link>
)}
{doc.docs?.map((item) => (
<Link
key={item.route}
href={item.route as any}
className={cn(
badgeVariants({
variant: item.route?.includes('components')
? 'default'
: 'secondary',
})
)}
>
{item.title}
</Link>
))}
</div>
) : null}
<div className="pb-12 pt-8">
<Mdx code={doc.body.code} packageInfo={packageInfo} />
</div>
<DocsPager doc={doc} />
</div>
{doc.toc && (
<div className="hidden text-sm xl:block">
<div className="sticky top-16 -mt-10 pt-4">
<ScrollArea className="h-full pb-10">
<div className="sticky top-16 -mt-10 h-[calc(100vh-3.5rem)] py-12">
<DashboardTableOfContents toc={toc} />
</div>
</ScrollArea>
</div>
</div>
)}
</main>
);
}