-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add redirect to English visiting pages without language specified
- Loading branch information
1 parent
30b0a0e
commit 315a5b6
Showing
2 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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/"); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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}`} /> |