From d62573745148e55003c98cad93b3d7e1ee2334e0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marcus=20Bl=C3=A4ttermann?= Date: Wed, 16 Nov 2022 20:32:16 +0100 Subject: [PATCH] Allow to handle directories for page creation --- website/pages/[slug].tsx | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/website/pages/[slug].tsx b/website/pages/[slug].tsx index bcfd64a7c..bf7111aa2 100644 --- a/website/pages/[slug].tsx +++ b/website/pages/[slug].tsx @@ -28,12 +28,21 @@ export const getStaticPaths: GetStaticPaths = async () => { // This function needs to be defined inside `getStaticPath` to be executed in executed in the correct context const loadFolder = (): Array<{ params: ParsedUrlQuery }> => fs - .readdirSync(path.join('docs')) - .map((filename) => ({ - params: { - slug: filename.replace('.mdx', ''), - }, - })) + .readdirSync(path.join('docs'), { withFileTypes: true }) + .flatMap((dirent: fs.Dirent) => { + if (dirent.isDirectory()) { + return [] + } + if (!dirent.name.includes('.mdx')) { + return [] + } + + return { + params: { + slug: dirent.name.replace('.mdx', ''), + }, + } + }) return { paths: loadFolder(),