ocelot.social/index.html
2025-11-24 17:42:26 +00:00

68 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 routePath = pathname.substring(1);
const { languages } = window.navigator;
const anchor = hash.substring(1);
const config = {"/de/":["de-DE","de"],"/en/":["en-US","en"],"/es/":["es-ES","es"],"/fr/":["fr-FR","fr"]};
const availableLocales = ["/en/","/de/","/es/","/fr/"];
const defaultLocale = "/de/";
const defaultBehavior = "defaultLocale"
let matchedLocalePath = null;
// get matched locale
findLanguage:
for (const lang of languages)
for (const [localePath, langs] of Object.entries(config))
if (langs.includes(lang)) {
matchedLocalePath = localePath;
break findLanguage;
}
// default link
const defaultLink = defaultLocale? `${origin}${defaultLocale}${routePath}${anchor? `#${anchor}`: ""}`: null;
// a locale matches
if (matchedLocalePath) {
const localeLink = `${origin}${matchedLocalePath}${routePath}${anchor? `#${anchor}`: ""}`;
if (availableLocales.includes(matchedLocalePath)) {
location.href = localeLink;
}
// the page does not exist
else {
// locale homepage
if (defaultBehavior === "homepage") {
location.href = `${origin}${matchedLocalePath}`;
}
// 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>