Skip to content

Commit

Permalink
Add redirect to English visiting pages without language specified
Browse files Browse the repository at this point in the history
  • Loading branch information
VisualEhrmanntraut committed Aug 17, 2024
1 parent 30b0a0e commit 315a5b6
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/content.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
import { getCollection } from "astro:content";

export const englishPages = await getCollection("docs", (entry) => {
return entry.slug.startsWith("en/");
});
28 changes: 28 additions & 0 deletions src/pages/[...enRedirectSlug].astro
Original file line number Diff line number Diff line change
@@ -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,
},
};
});
}
---

<meta http-equiv="refresh" content={`0;url=/${Astro.props.englishSlug}`} />

0 comments on commit 315a5b6

Please sign in to comment.