mirror of
https://github.com/gpxstudio/gpx.studio.git
synced 2025-08-31 15:43:25 +00:00
avoid more dynamic imports
This commit is contained in:
@@ -7,8 +7,8 @@ function getModule(language: string | undefined, guide: string) {
|
|||||||
[guide, subguide] = guide.split('/');
|
[guide, subguide] = guide.split('/');
|
||||||
}
|
}
|
||||||
return subguide
|
return subguide
|
||||||
? import(`./../../../lib/docs/${language}/${guide}/${subguide}.mdx`)
|
? import(`./../lib/docs/${language}/${guide}/${subguide}.mdx`)
|
||||||
: import(`./../../../lib/docs/${language}/${guide}.mdx`);
|
: import(`./../lib/docs/${language}/${guide}.mdx`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function load({ params }) {
|
export async function load({ params }) {
|
@@ -13,6 +13,10 @@
|
|||||||
import { goto } from '$app/navigation';
|
import { goto } from '$app/navigation';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
|
|
||||||
|
export let data: {
|
||||||
|
guideTitles: Record<string, string>;
|
||||||
|
};
|
||||||
|
|
||||||
const appRoutes = ['/[[language]]/app', '/[[language]]/embed'];
|
const appRoutes = ['/[[language]]/app', '/[[language]]/embed'];
|
||||||
|
|
||||||
onMount(() => {
|
onMount(() => {
|
||||||
@@ -29,26 +33,20 @@
|
|||||||
let lang = $page.params.language.replace('/', '');
|
let lang = $page.params.language.replace('/', '');
|
||||||
if ($locale !== lang) {
|
if ($locale !== lang) {
|
||||||
if (languages.hasOwnProperty(lang)) {
|
if (languages.hasOwnProperty(lang)) {
|
||||||
locale.set(lang);
|
$locale = lang;
|
||||||
} else if (browser) {
|
} else if (browser) {
|
||||||
goto(`${base}/404`);
|
goto(`${base}/404`);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if ($locale !== 'en') {
|
} else if ($locale !== 'en') {
|
||||||
locale.set('en');
|
$locale = 'en';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$: if (browser && !$isLoading && $locale) {
|
$: if (browser && !$isLoading && $locale) {
|
||||||
let title = `gpx.studio — ${$_(`metadata.${$page.route.id?.replace('/[[language]]', '').split('/')[1] ?? 'home'}_title`)}`;
|
let title = `gpx.studio — ${$_(`metadata.${$page.route.id?.replace('/[[language]]', '').split('/')[1] ?? 'home'}_title`)}`;
|
||||||
if ($page.params.guide) {
|
if ($page.params.guide) {
|
||||||
const [guide, subguide] = $page.params.guide.split('/');
|
document.title = `${title} | ${data.guideTitles[$page.params.guide]}`;
|
||||||
const promise = subguide
|
|
||||||
? import(`../lib/docs/${$locale ?? 'en'}/${guide}/${subguide}.mdx`)
|
|
||||||
: import(`../lib/docs/${$locale ?? 'en'}/${guide}.mdx`);
|
|
||||||
promise.then((module) => {
|
|
||||||
document.title = `${title} | ${module.metadata.title}`;
|
|
||||||
});
|
|
||||||
} else {
|
} else {
|
||||||
document.title = title;
|
document.title = title;
|
||||||
}
|
}
|
||||||
|
@@ -1,29 +0,0 @@
|
|||||||
import { getNextGuide, getPreviousGuide } from "$lib/components/docs/docs";
|
|
||||||
|
|
||||||
function getModule(language: string | undefined, guide: string) {
|
|
||||||
language = language ?? 'en';
|
|
||||||
let subguide = undefined;
|
|
||||||
if (guide.includes('/')) {
|
|
||||||
[guide, subguide] = guide.split('/');
|
|
||||||
}
|
|
||||||
return subguide
|
|
||||||
? import(`./../../../../lib/docs/${language}/${guide}/${subguide}.mdx`)
|
|
||||||
: import(`./../../../../lib/docs/${language}/${guide}.mdx`);
|
|
||||||
}
|
|
||||||
|
|
||||||
export async function load({ params }) {
|
|
||||||
const { guide, language } = params;
|
|
||||||
|
|
||||||
const previousGuide = getPreviousGuide(guide);
|
|
||||||
const nextGuide = getNextGuide(guide);
|
|
||||||
|
|
||||||
const previousGuideTitle = previousGuide ? (await getModule(language, previousGuide)).metadata.title : undefined;
|
|
||||||
const nextGuideTitle = nextGuide ? (await getModule(language, nextGuide)).metadata.title : undefined;
|
|
||||||
|
|
||||||
return {
|
|
||||||
previousGuide,
|
|
||||||
previousGuideTitle,
|
|
||||||
nextGuide,
|
|
||||||
nextGuideTitle
|
|
||||||
};
|
|
||||||
}
|
|
@@ -1,5 +1,6 @@
|
|||||||
<script lang="ts">
|
<script lang="ts">
|
||||||
import { page } from '$app/stores';
|
import { page } from '$app/stores';
|
||||||
|
import { getNextGuide, getPreviousGuide } from '$lib/components/docs/docs';
|
||||||
import DocsContainer from '$lib/components/docs/DocsContainer.svelte';
|
import DocsContainer from '$lib/components/docs/DocsContainer.svelte';
|
||||||
import { Button } from '$lib/components/ui/button';
|
import { Button } from '$lib/components/ui/button';
|
||||||
import { getURLForLanguage } from '$lib/utils';
|
import { getURLForLanguage } from '$lib/utils';
|
||||||
@@ -8,11 +9,11 @@
|
|||||||
|
|
||||||
export let data: {
|
export let data: {
|
||||||
guideModule: any;
|
guideModule: any;
|
||||||
previousGuide: string | undefined;
|
guideTitles: Record<string, string>;
|
||||||
previousGuideTitle: string | undefined;
|
|
||||||
nextGuide: string | undefined;
|
|
||||||
nextGuideTitle: string | undefined;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
$: previousGuide = getPreviousGuide($page.params.guide);
|
||||||
|
$: nextGuide = getNextGuide($page.params.guide);
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div class="markdown flex flex-col gap-3">
|
<div class="markdown flex flex-col gap-3">
|
||||||
@@ -20,23 +21,23 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div class="flex flex-row flex-wrap gap-3 pt-6">
|
<div class="flex flex-row flex-wrap gap-3 pt-6">
|
||||||
{#if data.previousGuide}
|
{#if previousGuide}
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
class="mr-auto"
|
class="mr-auto"
|
||||||
href={getURLForLanguage($locale, `/help/${data.previousGuide}`)}
|
href={getURLForLanguage($locale, `/help/${previousGuide}`)}
|
||||||
>
|
>
|
||||||
<ChevronLeft size="14" class="mr-1 mt-0.5" />
|
<ChevronLeft size="14" class="mr-1 mt-0.5" />
|
||||||
{data.previousGuideTitle}
|
{data.guideTitles[previousGuide]}
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
{#if data.nextGuide}
|
{#if nextGuide}
|
||||||
<Button
|
<Button
|
||||||
variant="outline"
|
variant="outline"
|
||||||
class="ml-auto"
|
class="ml-auto"
|
||||||
href={getURLForLanguage($locale, `/help/${data.nextGuide}`)}
|
href={getURLForLanguage($locale, `/help/${nextGuide}`)}
|
||||||
>
|
>
|
||||||
{data.nextGuideTitle}
|
{data.guideTitles[nextGuide]}
|
||||||
<ChevronRight size="14" class="ml-1 mt-0.5" />
|
<ChevronRight size="14" class="ml-1 mt-0.5" />
|
||||||
</Button>
|
</Button>
|
||||||
{/if}
|
{/if}
|
||||||
|
@@ -9,13 +9,12 @@ function getModule(language: string | undefined, guide: string) {
|
|||||||
: import(`./../../../../lib/docs/${language}/${guide}.mdx`);
|
: import(`./../../../../lib/docs/${language}/${guide}.mdx`);
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function load({ data, params }) {
|
export async function load({ params }) {
|
||||||
const { guide, language } = params;
|
const { guide, language } = params;
|
||||||
|
|
||||||
const guideModule = await getModule(language, guide);
|
const guideModule = await getModule(language, guide);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
guideModule,
|
guideModule,
|
||||||
...data,
|
|
||||||
};
|
};
|
||||||
}
|
}
|
Reference in New Issue
Block a user