diff --git a/src/content.ts b/src/content.ts new file mode 100644 index 0000000..5c9738a --- /dev/null +++ b/src/content.ts @@ -0,0 +1,5 @@ +import { getCollection } from "astro:content"; + +export const englishPages = await getCollection("docs", (entry) => { + return entry.slug.startsWith("en/"); +}); diff --git a/src/pages/[...enRedirectSlug].astro b/src/pages/[...enRedirectSlug].astro new file mode 100644 index 0000000..28a9108 --- /dev/null +++ b/src/pages/[...enRedirectSlug].astro @@ -0,0 +1,28 @@ +--- +import type { CollectionEntry } from 'astro:content'; +import { englishPages } from '~/content'; + +export const stripLangFromSlug = (slug: CollectionEntry<'docs'>['slug']) => { + let index = slug.indexOf("/"); + if (index == -1) { + return slug; + } else { + return slug.slice(index + 1); + } +}; + +export async function getStaticPaths() { + return englishPages.map((page) => { + return { + params: { + enRedirectSlug: stripLangFromSlug(page.slug), + }, + props: { + englishSlug: page.slug, + }, + }; + }); +} +--- + +