|
1 | | -import type { Metadata } from 'next'; |
2 | | -import type React from 'react'; |
3 | | -import { notFound } from 'next/navigation'; |
4 | | -import { evaluate } from '@mdx-js/mdx'; |
5 | | -import { Fragment } from 'react'; |
6 | | -import { jsx, jsxs } from 'react/jsx-runtime'; |
7 | | -import remarkGfm from 'remark-gfm'; |
8 | | - |
9 | | -import { BannerLink } from '../../../../components/docs/BannerLink'; |
10 | | -import { Card } from '../../../../components/docs/Card'; |
11 | | -import { CardGroup } from '../../../../components/docs/CardGroup'; |
12 | | -import { CodeGroup } from '../../../../components/docs/CodeGroup'; |
13 | | -import { DocsPageActions } from '../../../../components/docs/DocsPageActions'; |
14 | | -import { HighlightedPre } from '../../../../components/docs/HighlightedCode'; |
15 | | -import { Note } from '../../../../components/docs/Note'; |
16 | | -import { TableOfContents } from '../../../../components/docs/TableOfContents'; |
17 | | -import { Warning } from '../../../../components/docs/Warning'; |
18 | | -import styles from '../../../../components/docs/docs.module.css'; |
19 | | -import { getDoc } from '../../../../lib/docs'; |
20 | | -import { getDocMarkdownUrl } from '../../../../lib/docs-markdown'; |
21 | | -import { getAllDocSlugs } from '../../../../lib/docs-nav'; |
22 | | -import { absoluteUrl } from '../../../../lib/site'; |
23 | | - |
24 | | -function slugify(text: string): string { |
25 | | - return text |
26 | | - .toLowerCase() |
27 | | - .replace(/`([^`]+)`/g, '$1') |
28 | | - .replace(/[^a-z0-9]+/g, '-') |
29 | | - .replace(/^-|-$/g, ''); |
30 | | -} |
31 | | - |
32 | | -function HeadingWithId(level: 2 | 3) { |
33 | | - return function Heading({ children, ...props }: React.HTMLAttributes<HTMLHeadingElement>) { |
34 | | - const text = typeof children === 'string' ? children : String(children); |
35 | | - const id = slugify(text); |
36 | | - const Tag = `h${level}` as const; |
37 | | - return ( |
38 | | - <Tag id={id} {...props}> |
39 | | - {children} |
40 | | - </Tag> |
41 | | - ); |
42 | | - }; |
43 | | -} |
44 | | - |
45 | | -const components = { |
46 | | - BannerLink, |
47 | | - Card, |
48 | | - CardGroup, |
49 | | - CodeGroup, |
50 | | - Note, |
51 | | - Warning, |
52 | | - pre: HighlightedPre, |
53 | | - h2: HeadingWithId(2), |
54 | | - h3: HeadingWithId(3), |
55 | | -}; |
| 1 | +import { redirect } from 'next/navigation'; |
56 | 2 |
|
57 | 3 | type PageProps = { |
58 | 4 | params: Promise<{ slug: string }>; |
59 | 5 | }; |
60 | 6 |
|
61 | | -export async function generateStaticParams() { |
62 | | - return getAllDocSlugs().map((slug) => ({ slug })); |
63 | | -} |
64 | | - |
65 | | -export async function generateMetadata({ params }: PageProps): Promise<Metadata> { |
| 7 | +export default async function V8DocsSlugRedirectPage({ params }: PageProps) { |
66 | 8 | const { slug } = await params; |
67 | | - const doc = getDoc(slug, 'v8'); |
68 | | - |
69 | | - if (!doc) { |
70 | | - return { title: 'Not Found' }; |
71 | | - } |
72 | | - |
73 | | - return { |
74 | | - title: `${doc.frontmatter.title} - Version 8.0.0`, |
75 | | - description: doc.frontmatter.description, |
76 | | - alternates: { |
77 | | - canonical: absoluteUrl(`/docs/8.0.0/${slug}`), |
78 | | - }, |
79 | | - openGraph: { |
80 | | - title: `${doc.frontmatter.title} - Version 8.0.0`, |
81 | | - description: doc.frontmatter.description, |
82 | | - url: absoluteUrl(`/docs/8.0.0/${slug}`), |
83 | | - type: 'article', |
84 | | - }, |
85 | | - }; |
86 | | -} |
87 | | - |
88 | | -export default async function V8DocsPage({ params }: PageProps) { |
89 | | - const { slug } = await params; |
90 | | - const doc = getDoc(slug, 'v8'); |
91 | | - |
92 | | - if (!doc) { |
93 | | - notFound(); |
94 | | - } |
95 | | - |
96 | | - const { default: MDXContent } = await evaluate(doc.content, { |
97 | | - Fragment, |
98 | | - jsx, |
99 | | - jsxs, |
100 | | - remarkPlugins: [remarkGfm], |
101 | | - } as Parameters<typeof evaluate>[1]); |
102 | | - |
103 | | - const pageUrl = absoluteUrl(`/docs/8.0.0/${slug}`); |
104 | | - const markdownPath = `/docs/markdown/${slug}.md`; |
105 | | - const markdownUrl = getDocMarkdownUrl(slug); |
106 | | - |
107 | | - return ( |
108 | | - <div className={styles.articleWrapper}> |
109 | | - <article className={styles.article}> |
110 | | - <div className={styles.articleHeader}> |
111 | | - <div className={styles.articleHeading}> |
112 | | - <h1>{doc.frontmatter.title}</h1> |
113 | | - </div> |
114 | | - <DocsPageActions |
115 | | - title={doc.frontmatter.title} |
116 | | - pageUrl={pageUrl} |
117 | | - markdownPath={markdownPath} |
118 | | - markdownUrl={markdownUrl} |
119 | | - /> |
120 | | - </div> |
121 | | - {doc.frontmatter.description && ( |
122 | | - <p className={styles.articleDescription}>{doc.frontmatter.description}</p> |
123 | | - )} |
124 | | - <div className={styles.articleBody}> |
125 | | - <MDXContent components={components} /> |
126 | | - </div> |
127 | | - </article> |
128 | | - <aside className={styles.tocSidebar}> |
129 | | - <TableOfContents items={doc.toc} /> |
130 | | - </aside> |
131 | | - </div> |
132 | | - ); |
| 9 | + redirect(`/docs/${slug}`); |
133 | 10 | } |
0 commit comments