summaryrefslogtreecommitdiff
path: root/examples/docs/src/pages/index.astro
diff options
context:
space:
mode:
authorGravatar Okiki <okikio.dev@gmail.com> 2021-08-14 00:58:00 +0000
committerGravatar Fred K. Schott <fkschott@gmail.com> 2021-08-26 12:15:33 -0700
commitb7ada11ddbabe4dd2f0798e140e5b280de4d6952 (patch)
treec01ff3eee4f770fc108c19d126dce31d9cbe5e51 /examples/docs/src/pages/index.astro
parent59cc62f7bd53dbcb6ad8051fa501b7b797614178 (diff)
downloadastro-b7ada11ddbabe4dd2f0798e140e5b280de4d6952.tar.gz
astro-b7ada11ddbabe4dd2f0798e140e5b280de4d6952.tar.zst
astro-b7ada11ddbabe4dd2f0798e140e5b280de4d6952.zip
WIP update examples/docs/
Diffstat (limited to 'examples/docs/src/pages/index.astro')
-rw-r--r--examples/docs/src/pages/index.astro24
1 files changed, 24 insertions, 0 deletions
diff --git a/examples/docs/src/pages/index.astro b/examples/docs/src/pages/index.astro
new file mode 100644
index 000000000..f5a8fd318
--- /dev/null
+++ b/examples/docs/src/pages/index.astro
@@ -0,0 +1,24 @@
+---
+import Layout from '../layouts/MainLayout.astro';
+import { KNOWN_LANGUAGES } from "../languages";
+---
+<div id="known_languages" hidden>{KNOWN_LANGUAGES.join(",")}</div>
+<script>
+ // WIP: trigger a client-side redirect based on the browser language.
+ // A vercel.json redirect is enforced in production, so no user should ever see this page.
+ // Remove the vercel.json redirect when this is ready.
+ const KNOWN_LANGUAGES = document.querySelector("#known_languages")?.textContent?.split(",") ?? ['bg', 'de','en','es','fi','nl','pt-br','zh-CN','zh-TW', 'fr'];
+ let newLangWithRegion = (window.navigator.userLanguage || window.navigator.language || 'en-US').substr(0, 5);
+ let newLang = newLangWithRegion.substr(0, 2);
+
+ let langPathRegex = new RegExp(`\/(${KNOWN_LANGUAGES.join("|")})\/`);
+ let actualDest = window.location.pathname.replace(langPathRegex, "/");
+ if (actualDest == "/") actualDest = `/introduction`;
+ if (KNOWN_LANGUAGES.includes(newLangWithRegion)) {
+ window.location.pathname = '/' + newLangWithRegion + actualDest;
+ } else if (KNOWN_LANGUAGES.includes(newLang)) {
+ window.location.pathname = '/' + newLang + actualDest;
+ } else {
+ window.location.pathname = actualDest;
+ }
+</script>