Extract logic

This commit is contained in:
Marcus Blättermann 2022-11-16 20:48:13 +01:00
parent 84f8b2fcbd
commit 9d9f5cc8ba
No known key found for this signature in database
GPG Key ID: A1E1F04008AC450D

View File

@ -50,22 +50,26 @@ export const getStaticPaths: GetStaticPaths<ParsedUrlQuery> = async () => {
} }
} }
const getPathFull = (slug: ReadonlyArray<string>): ReadonlyArray<string> => slug
export const getStaticProps: GetStaticProps<PropsPage, ParsedUrlQuery> = async (args) => { export const getStaticProps: GetStaticProps<PropsPage, ParsedUrlQuery> = async (args) => {
if (!args.params) { if (!args.params) {
return { notFound: true } return { notFound: true }
} }
return {
props: { const pathFull = getPathFull(args.params.slug)
slug: args.params.slug,
mdx: await serialize( const mdx = await serialize(fs.readFileSync(`${path.join('docs', ...pathFull)}.mdx`, 'utf-8'), {
fs.readFileSync(`${path.join('docs', ...args.params.slug)}.mdx`, 'utf-8'),
{
parseFrontmatter: true, parseFrontmatter: true,
mdxOptions: { mdxOptions: {
remarkPlugins, remarkPlugins,
}, },
} })
),
return {
props: {
slug: args.params.slug,
mdx,
}, },
} }
} }