mirror of
https://github.com/explosion/spaCy.git
synced 2025-02-19 13:00:35 +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
|
export default PostPage
|
||||||
|
|
||||||
type ParsedUrlQuery = {
|
type ParsedUrlQuery = {
|
||||||
slug: string
|
listPathPage: Array<string>
|
||||||
}
|
}
|
||||||
|
|
||||||
export const getStaticPaths: GetStaticPaths<ParsedUrlQuery> = async () => {
|
export const getStaticPaths: GetStaticPaths<ParsedUrlQuery> = async () => {
|
||||||
// This function needs to be defined inside `getStaticPath` to be executed in executed in the correct context
|
// 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
|
fs
|
||||||
.readdirSync(path.join('docs'), { withFileTypes: true })
|
.readdirSync(path.join('docs', ...pathBase), { withFileTypes: true })
|
||||||
.flatMap((dirent: fs.Dirent) => {
|
.flatMap((dirent: fs.Dirent) => {
|
||||||
if (dirent.isDirectory()) {
|
if (dirent.isDirectory()) {
|
||||||
return []
|
return loadFolder([...pathBase, dirent.name])
|
||||||
}
|
}
|
||||||
if (!dirent.name.includes('.mdx')) {
|
if (!dirent.name.includes('.mdx')) {
|
||||||
return []
|
return []
|
||||||
|
@ -39,7 +39,7 @@ export const getStaticPaths: GetStaticPaths<ParsedUrlQuery> = async () => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
params: {
|
params: {
|
||||||
slug: dirent.name.replace('.mdx', ''),
|
listPathPage: [...pathBase, dirent.name.replace('.mdx', '')],
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
@ -56,9 +56,8 @@ export const getStaticProps: GetStaticProps<PropsPage, ParsedUrlQuery> = async (
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
props: {
|
props: {
|
||||||
slug: args.params.slug,
|
|
||||||
mdx: await serialize(
|
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,
|
parseFrontmatter: true,
|
||||||
mdxOptions: {
|
mdxOptions: {
|
Loading…
Reference in New Issue
Block a user