|
| 1 | +import { Article, Layout } from "mdxx-ssg-components"; |
| 2 | +import { GetStaticProps } from "next"; |
| 3 | +import ReactDOMServer from "react-dom/server"; |
| 4 | +import pages from "../gen/pages.json"; |
| 5 | +import ssgConfig from "../mdxx-ssg.json"; |
| 6 | +import Head from "next/head"; |
| 7 | + |
| 8 | +type Props = { |
| 9 | + slug: string; |
| 10 | + toc: Array<any>; |
| 11 | + history: Array<any>; |
| 12 | + frontmatter: { |
| 13 | + title: string; |
| 14 | + created: number; |
| 15 | + tags?: string[]; |
| 16 | + }; |
| 17 | + tags: string[]; |
| 18 | + html: string; |
| 19 | +}; |
| 20 | + |
| 21 | +export const config = { amp: true }; |
| 22 | + |
| 23 | +export function getStaticPaths() { |
| 24 | + const paths = pages.map((page) => { |
| 25 | + return `/${page.slug}`; |
| 26 | + }); |
| 27 | + return { |
| 28 | + paths, |
| 29 | + fallback: false, |
| 30 | + }; |
| 31 | +} |
| 32 | + |
| 33 | +export const getStaticProps: GetStaticProps = async (props) => { |
| 34 | + const slug = props.params.slug; |
| 35 | + const { frontmatter, default: Doc, toc } = await import( |
| 36 | + `../docs/${slug}.mdx` |
| 37 | + ); |
| 38 | + const { default: history } = await import(`../gen/${slug}.history.json`); |
| 39 | + return { |
| 40 | + props: { |
| 41 | + slug, |
| 42 | + toc, |
| 43 | + history, |
| 44 | + tags: frontmatter.tags || [], |
| 45 | + frontmatter: frontmatter || { title: slug, created: 0, tags: [] }, |
| 46 | + html: ReactDOMServer.renderToStaticMarkup(<Doc amp />), |
| 47 | + } as Props, |
| 48 | + }; |
| 49 | +}; |
| 50 | + |
| 51 | +export default (props: Props) => ( |
| 52 | + <> |
| 53 | + <Head> |
| 54 | + <title> |
| 55 | + {props.frontmatter.title} - {ssgConfig.siteName} |
| 56 | + </title> |
| 57 | + </Head> |
| 58 | + <Layout ssgConfig={ssgConfig}> |
| 59 | + <Article |
| 60 | + ssgConfig={ssgConfig} |
| 61 | + history={props.history} |
| 62 | + toc={props.toc} |
| 63 | + title={props.frontmatter.title} |
| 64 | + tags={props.tags} |
| 65 | + > |
| 66 | + <div |
| 67 | + className="markdown-body" |
| 68 | + dangerouslySetInnerHTML={{ __html: props.html }} |
| 69 | + /> |
| 70 | + </Article> |
| 71 | + </Layout> |
| 72 | + </> |
| 73 | +); |
0 commit comments