Added homepage and moved old homepage to aboutme page
This commit is contained in:
@@ -1,77 +1,32 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<title>Redirecting...</title>
|
||||
<style>
|
||||
/* Example minimal styling */
|
||||
body {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
min-height: 100vh;
|
||||
font-family: sans-serif;
|
||||
background-color: #f9fafb;
|
||||
color: #374151;
|
||||
}
|
||||
.container {
|
||||
text-align: center;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
<div class="container">
|
||||
<h1 class="text-2xl font-bold mb-4">Redirecting...</h1>
|
||||
<p id="redirect-message">
|
||||
You are being redirected to the <strong></strong> version of our site.
|
||||
</p>
|
||||
<p class="mt-4">
|
||||
If you are not redirected automatically, please
|
||||
<a id="redirect-link" href="" class="text-blue-500 underline">click here</a>.
|
||||
</p>
|
||||
</div>
|
||||
|
||||
<script type="module">
|
||||
// Define the supported languages
|
||||
const supportedLangs = ['en', 'nl', 'de'];
|
||||
let chosenLang = 'nl'; // Default language
|
||||
---
|
||||
export const prerender = false;
|
||||
import { supportedLanguages } from '~/i18n/translations';
|
||||
|
||||
// Get the user's language from the browser
|
||||
const userLang = navigator.language || (navigator.languages && navigator.languages[0]);
|
||||
|
||||
if (userLang) {
|
||||
// For example, "en-US" becomes "en"
|
||||
const preferredLang = userLang.split('-')[0];
|
||||
if (supportedLangs.includes(preferredLang)) {
|
||||
chosenLang = preferredLang;
|
||||
}
|
||||
}
|
||||
|
||||
// Construct the target URL based on the chosen language
|
||||
const targetURL = `/${chosenLang}`;
|
||||
console.log("Target URL:", targetURL);
|
||||
// Check for language preference in cookies (set by client-side JS)
|
||||
const cookies = Astro.request.headers.get('cookie') || '';
|
||||
const cookieLanguage = cookies.split(';')
|
||||
.map(cookie => cookie.trim())
|
||||
.find(cookie => cookie.startsWith('preferredLanguage='))
|
||||
?.split('=')[1];
|
||||
|
||||
// Update the DOM with the computed language values:
|
||||
// Update the redirect message to display the chosen language.
|
||||
const messageEl = document.getElementById('redirect-message');
|
||||
if (messageEl) {
|
||||
messageEl.innerHTML = `You are being redirected to the <strong>${chosenLang.toUpperCase()}</strong> version of our site.`;
|
||||
}
|
||||
// Get the user's preferred language from the browser if no cookie
|
||||
const acceptLanguage = Astro.request.headers.get('accept-language') || '';
|
||||
// Define the type for supported languages
|
||||
type SupportedLanguage = typeof supportedLanguages[number];
|
||||
|
||||
// Update the href for the clickable link.
|
||||
const linkEl = document.getElementById('redirect-link');
|
||||
if (linkEl) {
|
||||
linkEl.href = targetURL;
|
||||
}
|
||||
// Use cookie language if available, otherwise detect from browser
|
||||
const preferredLanguage =
|
||||
(cookieLanguage && supportedLanguages.includes(cookieLanguage as SupportedLanguage))
|
||||
? cookieLanguage
|
||||
: acceptLanguage
|
||||
.split(',')
|
||||
.map(lang => lang.split(';')[0].trim().substring(0, 2))
|
||||
.find(lang => supportedLanguages.includes(lang as SupportedLanguage)) || 'en';
|
||||
|
||||
// Option 1: Dynamically add a meta refresh tag.
|
||||
const metaRefresh = document.createElement("meta");
|
||||
metaRefresh.httpEquiv = "refresh";
|
||||
metaRefresh.content = `0; url=${targetURL}`;
|
||||
document.head.appendChild(metaRefresh);
|
||||
// Get the hash fragment if present
|
||||
const url = new URL(Astro.request.url);
|
||||
const hash = url.hash;
|
||||
|
||||
// Option 2: Alternatively, use JavaScript redirection:
|
||||
// window.location.href = targetURL;
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
// Redirect to the language-specific homepage
|
||||
return Astro.redirect(`/${preferredLanguage}/${hash}`);
|
||||
---
|
Reference in New Issue
Block a user