Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustinMauroy committed Dec 12, 2024
1 parent 2641754 commit a4b8af5
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 24 deletions.
9 changes: 9 additions & 0 deletions content/projects/index.en.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ title: My Projects
description: A list of projects I've contributed to or created.
---

<ProjectCard
title="nodejs-loaders"
description="A collection of loaders to facilitate a quick and easy local development and CI testing environment."
link={{
href: 'https://github.com/nodejs-loaders/nodejs-loaders',
label: 'nodejs-loaders/nodejs-loaders',
}}
/>

<ProjectCard
title="ScholarSuite"
description="ScholarSuite is a school management application. It lets you manage attendance, subjects and grades."
Expand Down
9 changes: 9 additions & 0 deletions content/projects/index.fr.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ title: Mes Projets
description: Une liste de projets auxquels j'ai contribué ou que j'ai créés.
---

<ProjectCard
title="nodejs-loaders"
description="Une collection de chargeurs pour faciliter un développement local rapide et facile et un environnement de test CI."
link={{
href: 'https://github.com/nodejs-loaders/nodejs-loaders',
label: 'nodejs-loaders/nodejs-loaders',
}}
/>

<ProjectCard
title="ScholarSuite"
description="ScholarSuite est une application de gestion scolaire. Elle permet de gérer les présences, les matières et les notes."
Expand Down
37 changes: 13 additions & 24 deletions lib/content.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import fs from 'node:fs/promises';
import path from 'node:path';
import { readFile, readdir } from 'node:fs/promises';
import { join } from 'node:path';
import { isNodeError } from '~/utils/node';
import compileMDX from './mdx.ts';

Expand All @@ -9,34 +9,23 @@ type GetContentProps = {
slug?: string;
};

const BASE_CONTENT_PATH = path.join(process.cwd(), 'content');
const BASE_CONTENT_PATH = join(process.cwd(), 'content');

export const getContent = async ({
section,
lang,
slug = 'index',
}: GetContentProps): Promise<string | null> => {
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 = {
Expand All @@ -48,8 +37,8 @@ export const getSlugs = async ({
section,
lang = 'en',
}: GetSlugsProps): Promise<string[]> => {
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`))
Expand Down

0 comments on commit a4b8af5

Please sign in to comment.