import { base } from '$app/paths'; import { languages } from '$lib/languages'; import { getURLForLanguage } from '$lib/utils'; export async function handle({ event, resolve }) { const language = event.params.language ?? 'en'; const strings = await import(`./locales/${language}.json`); const path = event.url.pathname; const page = event.route.id?.replace('/[[language]]', '').split('/')[1] ?? 'home'; let title = strings.metadata[`${page}_title`]; const description = strings.metadata[`description`]; if (page === 'help' && event.params.guide) { const [guide, subguide] = event.params.guide.split('/'); const guideModule = subguide ? await import(`./lib/docs/${language}/${guide}/${subguide}.mdx`) : await import(`./lib/docs/${language}/${guide}.mdx`); title = `${title} | ${guideModule.metadata.title}`; } const htmlTag = ``; let headTag = ` gpx.studio — ${title} `; for (let lang of Object.keys(languages)) { headTag += ` `; } const stringsHTML = page === 'app' ? stringsToHTML(strings) : ''; const response = await resolve(event, { transformPageChunk: ({ html }) => html.replace('', htmlTag).replace('', headTag).replace('', `
${stringsHTML}
`) }); return response; } function stringsToHTML(dictionary, strings = new Set(), root = true) { Object.values(dictionary).forEach((value) => { if (typeof value === 'object') { stringsToHTML(value, strings, false); } else { strings.add(value); } }); if (root) { return Array.from(strings).map((string) => `

${string}

`).join(''); } }