Skip to content

Commit 536ff21

Browse files
committed
trainings pagina engels werkt
1 parent db66267 commit 536ff21

File tree

6 files changed

+49
-21
lines changed

6 files changed

+49
-21
lines changed

content/trainingen/_.en._.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: "not found"
3+
img: "_.jpg"
4+
alt: ""
5+
volgnummer: ""
6+
---
7+
8+
# The requested page could not be found

content/trainingen/_.jpg

26.4 KB
Loading

content/trainingen/_.nl._.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
---
2+
title: "niet gevonden"
3+
img: "_.jpg"
4+
alt: ""
5+
volgnummer: ""
6+
---
7+
8+
# De gevraagde pagina kon niet worden gevonden

src/lib/utils/index.ts

Lines changed: 21 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,42 @@
1-
const importPaths = {
1+
import type { AvailableLanguageTag } from '$lib/paraglide/runtime.js';
2+
const importPathsNl = {
23
blog: import.meta.glob('$content/blog/*.nl.md'),
34
coaching: import.meta.glob('$content/coaching/*.nl.md'),
45
opdrachtgevers: import.meta.glob('$content/opdrachtgevers/*.nl.md'),
56
team: import.meta.glob('$content/team/*.nl.md'),
67
trainingen: import.meta.glob('$content/trainingen/*.nl.md')
78
};
9+
const importPathsEn = {
10+
blog: import.meta.glob('$content/blog/*.en.md'),
11+
coaching: import.meta.glob('$content/coaching/*.en.md'),
12+
opdrachtgevers: import.meta.glob('$content/opdrachtgevers/*.en.md'),
13+
team: import.meta.glob('$content/team/*.en.md'),
14+
trainingen: import.meta.glob('$content/trainingen/*.en.md')
15+
};
16+
17+
const importPathsMap = {
18+
nl: importPathsNl,
19+
en: importPathsEn
20+
};
821

9-
const validCategories = ['blog', 'coaching', 'opdrachtgevers', 'team', 'trainingen'];
1022

11-
export const fetchContent = async (category) => {
12-
if (!validCategories.includes(category)) {
13-
throw new Error('Invalid category');
14-
}
23+
type ValidCategory = 'blog' | 'coaching' | 'opdrachtgevers' | 'team' | 'trainingen';
1524

16-
const allPostFiles = importPaths[category];
17-
const iterablePostFiles = Object.entries(allPostFiles);
25+
export const fetchContent = async (category: ValidCategory, language: AvailableLanguageTag) => {
26+
const importPaths = importPathsMap[language];
27+
const allPostFiles = importPaths[category];
28+
const iterablePostFiles = Object.entries(allPostFiles);
1829

1930
const allPosts = await Promise.all(
2031
iterablePostFiles.map(async ([path, resolver]) => {
2132
const { metadata } = await resolver();
22-
const postPath = path.replace(`/content/${category}/`, '').replace('.nl.md', '');
33+
const postPath = path.replace(`/content/${category}/`, '').replace(`.${language}.md`, '');
2334
return {
2435
meta: metadata,
2536
path: postPath
2637
};
2738
})
2839
);
2940

30-
return allPosts;
41+
return allPosts;
3142
};

src/routes/trainingen/+page.svelte

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,10 @@
4242
onMount(() => {
4343
trainings = Object.entries(TrainingModules)
4444
.map(([path, module]) => ({
45-
path: path.replace(/\.nl\.md$/, ''),
45+
path: path.replace(/\.(nl|en)\.md$/, ''),
4646
name:
4747
path
48-
.replace(/\.nl\.md$/, '')
48+
.replace(/\.(nl|en)\.md$/, '')
4949
.split('/')
5050
.pop() || path,
5151
meta: module.metadata,

src/routes/trainingen/[training_title]/+page.ts

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
import { fetchContent } from '$lib/utils';
2+
import { languageTag } from '$lib/paraglide/runtime.js';
3+
export async function load({ depends, params }) {
4+
depends("paraglide:lang");
5+
let post;
6+
try {
7+
post = await import(`$content/trainingen/${params.training_title}.${languageTag()}.md`);
8+
} catch (error) {
9+
post = await import(`$content/trainingen/_.${languageTag()}._.md`);
10+
}
211

3-
export async function load({ params }) {
4-
const post = await import(`$content/trainingen/${params.training_title}.md`);
512
const { title, date, img, springest } = post.metadata;
613
const content = post.default;
714

8-
const allPosts = await fetchContent('trainingen');
15+
const allPosts = await fetchContent('trainingen', languageTag());
916
const sortedPosts = allPosts.sort((a, b) => a.meta.volgnummer - b.meta.volgnummer);
1017

1118
const currentIndex = sortedPosts.findIndex((p) => p.path === params.training_title);
@@ -23,10 +30,4 @@ export async function load({ params }) {
2330
};
2431
}
2532

26-
/** @type {import('./$types').EntryGenerator} */
27-
export async function entries() {
28-
const allPosts = await fetchContent('trainingen');
29-
return allPosts.map((post) => ({ training_title: post.path }));
30-
}
31-
3233
export const prerender = true;

0 commit comments

Comments
 (0)