mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.Docs.git
synced 2025-11-19 21:16:31 +08:00
69 lines
1.9 KiB
HTML
69 lines
1.9 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="robots" content="noindex">
|
|
<title>Redirecting...</title>
|
|
<script>
|
|
const { hash, origin, pathname } = window.location;
|
|
const { languages } = window.navigator;
|
|
const anchor = hash.substr(1);
|
|
|
|
const localeConfig = {"/en/":["en-US","en-UK","en"],"/":["zh-CN","zh-TW","zh"]};
|
|
const availableLocales = ["/en/"];
|
|
const defaultLocale = availableLocales.pop();
|
|
const defaultBehavior = "defaultLocale"
|
|
|
|
let localePath = null;
|
|
|
|
// get matched locale
|
|
findLanguage:
|
|
for (const lang of languages)
|
|
for (const [path, langs] of Object.entries(localeConfig))
|
|
if (langs.includes(lang)) {
|
|
if (!availableLocales.includes(path))
|
|
continue;
|
|
localePath = path;
|
|
break findLanguage;
|
|
}
|
|
|
|
// default link
|
|
const defaultLink = defaultLocale? `${origin}${defaultLocale}${pathname.substring(1)}${anchor?`#${anchor}`:""}`: null;
|
|
|
|
// a locale matches
|
|
if (localePath) {
|
|
const localeLink = `${origin}${localePath}${pathname.substring(1)}${anchor?`#${anchor}`:""}`;
|
|
|
|
if (availableLocales.includes(localePath)) {
|
|
location.href = localeLink;
|
|
}
|
|
// the page does not exist
|
|
else {
|
|
// locale homepage
|
|
if (defaultBehavior === "homepage") {
|
|
location.href = `${origin}${localePath}`;
|
|
}
|
|
// default locale page
|
|
else if (defaultBehavior === "defaultLocale" && defaultLink) {
|
|
location.href = defaultLink;
|
|
}
|
|
// as is to get a 404 page of that locale
|
|
else {
|
|
location.href = localeLink;
|
|
}
|
|
}
|
|
}
|
|
// we have a default page
|
|
else if (defaultLink) {
|
|
location.href = defaultLink;
|
|
}
|
|
else {
|
|
location.href = `${origin}/404.html`;
|
|
}
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<p>Redirecting...</p>
|
|
</body>
|
|
</html>
|