Extract function

This will make the next commit easier to read
This commit is contained in:
Marcus Blättermann 2022-11-16 18:18:04 +01:00
parent aea5496788
commit 4151870c9f
No known key found for this signature in database
GPG Key ID: A1E1F04008AC450D

View File

@ -25,12 +25,18 @@ type ParsedUrlQuery = {
} }
export const getStaticPaths: GetStaticPaths<ParsedUrlQuery> = async () => { export const getStaticPaths: GetStaticPaths<ParsedUrlQuery> = async () => {
return { // This function needs to be defined inside `getStaticPath` to be executed in executed in the correct context
paths: fs.readdirSync(path.join('docs')).map((filename) => ({ const loadFolder = (): Array<{ params: ParsedUrlQuery }> =>
fs
.readdirSync(path.join('docs'))
.map((filename) => ({
params: { params: {
slug: filename.replace('.mdx', ''), slug: filename.replace('.mdx', ''),
}, },
})), }))
return {
paths: loadFolder(),
fallback: false, fallback: false,
} }
} }