mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-14 10:30:34 +03:00
Allow to parse subfolders for pages
This commit is contained in:
parent
7c31de6c34
commit
6fa2bf2fff
|
@ -21,17 +21,17 @@ const PostPage = ({ mdx: mdx }: PropsPage) => {
|
|||
export default PostPage
|
||||
|
||||
type ParsedUrlQuery = {
|
||||
slug: string
|
||||
listPathPage: Array<string>
|
||||
}
|
||||
|
||||
export const getStaticPaths: GetStaticPaths<ParsedUrlQuery> = async () => {
|
||||
// This function needs to be defined inside `getStaticPath` to be executed in executed in the correct context
|
||||
const loadFolder = (): Array<{ params: ParsedUrlQuery }> =>
|
||||
const loadFolder = (pathBase: Array<string> = []): Array<{ params: ParsedUrlQuery }> =>
|
||||
fs
|
||||
.readdirSync(path.join('docs'), { withFileTypes: true })
|
||||
.readdirSync(path.join('docs', ...pathBase), { withFileTypes: true })
|
||||
.flatMap((dirent: fs.Dirent) => {
|
||||
if (dirent.isDirectory()) {
|
||||
return []
|
||||
return loadFolder([...pathBase, dirent.name])
|
||||
}
|
||||
if (!dirent.name.includes('.mdx')) {
|
||||
return []
|
||||
|
@ -39,7 +39,7 @@ export const getStaticPaths: GetStaticPaths<ParsedUrlQuery> = async () => {
|
|||
|
||||
return {
|
||||
params: {
|
||||
slug: dirent.name.replace('.mdx', ''),
|
||||
listPathPage: [...pathBase, dirent.name.replace('.mdx', '')],
|
||||
},
|
||||
}
|
||||
})
|
||||
|
@ -56,9 +56,8 @@ export const getStaticProps: GetStaticProps<PropsPage, ParsedUrlQuery> = async (
|
|||
}
|
||||
return {
|
||||
props: {
|
||||
slug: args.params.slug,
|
||||
mdx: await serialize(
|
||||
fs.readFileSync(`${path.join('docs', args.params.slug)}.mdx`, 'utf-8'),
|
||||
fs.readFileSync(`${path.join('docs', ...args.params.listPathPage)}.mdx`, 'utf-8'),
|
||||
{
|
||||
parseFrontmatter: true,
|
||||
mdxOptions: {
|
Loading…
Reference in New Issue
Block a user