From a4b8af5667af14f5c154368470b65c91aa55ff19 Mon Sep 17 00:00:00 2001 From: Augustin Mauroy <97875033+AugustinMauroy@users.noreply.github.com> Date: Thu, 12 Dec 2024 09:37:20 +0100 Subject: [PATCH] update --- content/projects/index.en.mdx | 9 +++++++++ content/projects/index.fr.mdx | 9 +++++++++ lib/content.ts | 37 ++++++++++++----------------------- 3 files changed, 31 insertions(+), 24 deletions(-) diff --git a/content/projects/index.en.mdx b/content/projects/index.en.mdx index 7f7f75a..211f318 100644 --- a/content/projects/index.en.mdx +++ b/content/projects/index.en.mdx @@ -3,6 +3,15 @@ title: My Projects description: A list of projects I've contributed to or created. --- + + + => { - try { - const filePath = path.join( - BASE_CONTENT_PATH, - section, - `${slug}.${lang}.mdx` - ); - - return fs.readFile(filePath, 'utf8'); - } catch { - try { - const defaultFilePath = path.join( - BASE_CONTENT_PATH, - section, - `${slug}.en.mdx` - ); + let filePath = join(BASE_CONTENT_PATH, section, `${slug}.${lang}.mdx`); - return fs.readFile(defaultFilePath, 'utf8'); - } catch { - return null; + return readFile(filePath, 'utf8').catch(() => { + if (lang !== 'en') { + filePath = join(BASE_CONTENT_PATH, section, `${slug}.en.mdx`); + return readFile(filePath, 'utf8').catch(() => null); } - } + + return null; + }); }; type GetSlugsProps = { @@ -48,8 +37,8 @@ export const getSlugs = async ({ section, lang = 'en', }: GetSlugsProps): Promise => { - const dirPath = path.join(BASE_CONTENT_PATH, section); - const files = await fs.readdir(dirPath); + const dirPath = join(BASE_CONTENT_PATH, section); + const files = await readdir(dirPath); return files .filter(file => file.endsWith(`.${lang}.mdx`))