mirror of
https://github.com/wukko/cobalt.git
synced 2025-02-02 16:36:20 +01:00
web/about: fix switching between pages
This commit is contained in:
parent
a1361e8462
commit
d2b1a6553b
2 changed files with 33 additions and 8 deletions
|
@ -1,10 +1,6 @@
|
||||||
<script>
|
<script lang="ts">
|
||||||
import locale from '$lib/i18n/locale';
|
import type { PageData } from './$types';
|
||||||
import { page } from '$app/stores';
|
export let data: PageData;
|
||||||
|
|
||||||
const component = import(`$i18n/${$locale}/about/${$page.params.page}.md`);
|
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
{#await component then component}
|
<svelte:component this={data.component} />
|
||||||
<svelte:component this={component.default} />
|
|
||||||
{/await}
|
|
||||||
|
|
29
web/src/routes/about/[page]/+page.ts
Normal file
29
web/src/routes/about/[page]/+page.ts
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
import type { ComponentType, SvelteComponent } from 'svelte';
|
||||||
|
import { get } from 'svelte/store';
|
||||||
|
import { error } from '@sveltejs/kit';
|
||||||
|
|
||||||
|
import type { PageLoad } from './$types';
|
||||||
|
|
||||||
|
import locale from '$lib/i18n/locale';
|
||||||
|
import type { DefaultImport } from '$lib/types/generic';
|
||||||
|
import { defaultLocale } from '$lib/i18n/translations';
|
||||||
|
|
||||||
|
const pages = import.meta.glob('$i18n/*/about/*.md');
|
||||||
|
|
||||||
|
export const load: PageLoad = async ({ params }) => {
|
||||||
|
const getPage = (locale: string) => Object.keys(pages).find(
|
||||||
|
file => file.endsWith(`${locale}/about/${params.page}.md`)
|
||||||
|
);
|
||||||
|
|
||||||
|
const componentPath = getPage(get(locale)) || getPage(defaultLocale);
|
||||||
|
if (componentPath) {
|
||||||
|
type Component = ComponentType<SvelteComponent>;
|
||||||
|
const componentImport = pages[componentPath] as DefaultImport<Component>;
|
||||||
|
|
||||||
|
return { component: (await componentImport()).default }
|
||||||
|
}
|
||||||
|
|
||||||
|
error(404, 'Not found');
|
||||||
|
};
|
||||||
|
|
||||||
|
export const prerender = true;
|
Loading…
Reference in a new issue