From 04b05c089626fc8e004f15ca6952158028b9a6fe Mon Sep 17 00:00:00 2001 From: Luccas Mateus de Medeiros Gomes Date: Sat, 29 Apr 2023 13:54:51 -0300 Subject: [PATCH] [learn-example][sm] - use getstaticprops --- examples/learn-example/pages/[[...path]].tsx | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/examples/learn-example/pages/[[...path]].tsx b/examples/learn-example/pages/[[...path]].tsx index 2b434ea5..1e869e32 100644 --- a/examples/learn-example/pages/[[...path]].tsx +++ b/examples/learn-example/pages/[[...path]].tsx @@ -3,7 +3,21 @@ import path from 'path'; import parse from '../lib/markdown'; import DRD from '../components/DRD'; -export const getServerSideProps = async (context) => { +export const getStaticPaths = async () => { + const contentDir = path.join(process.cwd(), '/content/'); + const contentFolders = await fs.readdir(contentDir, 'utf8'); + const paths = contentFolders.map((folder: string) => + folder === 'index.md' + ? { params: { path: [] } } + : { params: { path: [folder] } } + ); + return { + paths, + fallback: false, + }; +}; + +export const getStaticProps = async (context) => { let pathToFile = 'index.md'; if (context.params.path) { pathToFile = context.params.path.join('/') + '/index.md';