Restore old slug, 404 page
This commit is contained in:
@@ -12,8 +12,8 @@ interface Props {
|
||||
meta: { title: string; description?: string; hide_table_of_contents?: boolean }
|
||||
children: any
|
||||
toc?: any
|
||||
menuItems: any
|
||||
currentPage: string
|
||||
menuItems?: any
|
||||
currentPage?: string
|
||||
}
|
||||
|
||||
const Layout: FC<Props> = ({ meta, children, toc }) => {
|
||||
|
||||
@@ -5,7 +5,7 @@ interface Props {
|
||||
meta: { title: string; description?: string; hide_table_of_contents?: boolean; video?: string }
|
||||
children: any
|
||||
toc?: any
|
||||
currentPage: string
|
||||
currentPage?: string
|
||||
}
|
||||
|
||||
const Layout: FC<Props> = (props) => {
|
||||
|
||||
13
apps/docs/pages/404.mdx
Normal file
13
apps/docs/pages/404.mdx
Normal file
@@ -0,0 +1,13 @@
|
||||
import Layout from '~/layouts/DefaultGuideLayout'
|
||||
|
||||
export const meta = {
|
||||
id: '404',
|
||||
title: '404 not found',
|
||||
description: '404 not found',
|
||||
}
|
||||
|
||||
404 not found
|
||||
|
||||
export const Page = ({ children }) => <Layout meta={meta} children={children} />
|
||||
|
||||
export default Page
|
||||
74
apps/docs/pages/[...slug].tsx
Normal file
74
apps/docs/pages/[...slug].tsx
Normal file
@@ -0,0 +1,74 @@
|
||||
import toc from 'markdown-toc'
|
||||
import { MDXRemote } from 'next-mdx-remote'
|
||||
import { serialize } from 'next-mdx-remote/serialize'
|
||||
import components from '../components/index'
|
||||
import NewLayout from '~/layouts/DefaultGuideLayout'
|
||||
|
||||
import Layout from '~/layouts/Default'
|
||||
import { getAllDocs, getDocsBySlug } from '../lib/docs'
|
||||
|
||||
interface Meta {
|
||||
id: string
|
||||
title: string
|
||||
sidebar_label: string
|
||||
hide_table_of_contents: boolean
|
||||
}
|
||||
|
||||
interface Props {
|
||||
meta: Meta
|
||||
content: any
|
||||
toc: any
|
||||
}
|
||||
const isNewDocs = process.env.NEXT_PUBLIC_NEW_DOCS === 'true'
|
||||
|
||||
export default function Doc({ meta, content, toc }: Props) {
|
||||
return (
|
||||
// @ts-ignore
|
||||
<>
|
||||
{Object.entries(meta).length > 0 || !isNewDocs ? (
|
||||
<Layout meta={meta} toc={toc}>
|
||||
<MDXRemote {...content} components={components} />
|
||||
</Layout>
|
||||
) : (
|
||||
<NewLayout meta={meta} toc={toc}>
|
||||
<MDXRemote {...content} components={components} />
|
||||
</NewLayout>
|
||||
)}
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export async function getStaticProps({ params }: { params: { slug: string[] } }) {
|
||||
let slug
|
||||
if (params.slug.length > 1) {
|
||||
slug = `docs/${params.slug.join('/')}`
|
||||
} else {
|
||||
slug = `docs/${params.slug[0]}`
|
||||
}
|
||||
|
||||
let doc = getDocsBySlug(slug)
|
||||
const content = await serialize(doc.content || '')
|
||||
|
||||
return {
|
||||
props: {
|
||||
...doc,
|
||||
content,
|
||||
toc: toc(doc.content, { maxdepth: 1, firsth1: false }),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
export function getStaticPaths() {
|
||||
let docs = getAllDocs()
|
||||
|
||||
return {
|
||||
paths: docs.map(() => {
|
||||
return {
|
||||
params: {
|
||||
slug: docs.map((d) => d.slug),
|
||||
},
|
||||
}
|
||||
}),
|
||||
fallback: 'blocking',
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user