import path from 'path' ; import dotProp from 'dot-prop' ; import { GetStaticPaths , GetStaticPropsContext , InferGetStaticPropsType , } from 'next' ; import { Typography } from 'components/Typography' ; import { Layout } from 'components/docs/Layout' ; import { parse , renderToReact } from 'utils/markdown' ; const defaultSlug = [ 'introduction' , 'whats-marp' ] ; const docsCtx = ( ) => require . context ( 'docs' , true , /\.md$/ ) ; export const getStaticPaths = async ( ) => ( { paths : [ '/docs' , ... docsCtx ( ) . keys ( ) . map ( ( id ) => path . join ( '/docs/' , id ) . slice ( 0 , - 3 ) ) , ] , fallback : false , } ) ; export const getStaticProps = async ( { params } ) => { const { default : manifest } = await import ( 'docs/manifest.yaml' ) ; const slug = ( [ ] as string [ ] ) . concat ( params ?. slug ?? defaultSlug ) ; if ( slug [ 0 ] === 'docs' ) slug . splice ( 0 , 1 ) ; const { default : md } = await import ( `docs/${ path . join ( ... slug ) }.md` ) ; const { data , mdast } = await parse ( md ) ; const breadcrumbs = slug . map ( ( sl , i ) => { const slugs = slug . slice ( 0 , i + 1 ) ; const key = slugs . join ( '/' ) ; const data = dotProp . get < any > ( { pages : manifest } , slugs . flatMap ( ( s ) => [ 'pages' , s ] ) . join ( '.' ) ) ; const hasLink = docsCtx ( ) . keys ( ) . includes ( `./${ key }.md` ) ; return { key , title : data ?. title || sl , ... ( hasLink ? { link : `/docs/${ key }` } : { } ) , } ; } ) ; return { props : { breadcrumbs , data , manifest , mdast , slug } } ; } ; const Docs = ( { breadcrumbs , manifest , mdast , slug , } ) => ( < Layout breadcrumbs = { breadcrumbs } manifest = { manifest } slug = { slug } > { } < Typography key = { slug . join ( '/' ) } > { renderToReact ( mdast ) } < /Typography> < /Layout>); export default Docs ;