--- // header.astro import { Icon } from 'astro-icon/components'; import Logo from '~/components/Logo.astro'; import ToggleTheme from '~/components/common/ToggleTheme.astro'; import ToggleMenu from '~/components/common/ToggleMenu.astro'; import LanguageDropdown from '~/components/LanguageDropdown.astro'; import { getHomePermalink } from '~/utils/permalinks'; import { trimSlash } from '~/utils/permalinks'; import { getHeaderData } from '~/navigation'; interface Link { text?: string; href?: string; ariaLabel?: string; icon?: string; } interface MenuLink extends Link { links?: Array; isHashLink?: boolean; } export interface Props { id?: string; links?: Array; isSticky?: boolean; isDark?: boolean; isFullWidth?: boolean; showToggleTheme?: boolean; showRssFeed?: boolean; position?: string; } import { supportedLanguages } from '~/i18n/translations'; // Get current language from URL const currentPath = `/${trimSlash(new URL(Astro.url).pathname)}`; const pathSegments = currentPath.split('/').filter(Boolean); // Define the type for supported languages type SupportedLanguage = (typeof supportedLanguages)[number]; // Check for language in URL path let currentLang = pathSegments[0] && supportedLanguages.includes(pathSegments[0] as SupportedLanguage) ? (pathSegments[0] as SupportedLanguage) : null; // If no language in URL, check cookies if (!currentLang) { const cookies = Astro.request.headers.get('cookie') || ''; const cookieLanguage = cookies .split(';') .map((cookie) => cookie.trim()) .find((cookie) => cookie.startsWith('preferredLanguage=')) ?.split('=')[1]; if (cookieLanguage && supportedLanguages.includes(cookieLanguage as SupportedLanguage)) { currentLang = cookieLanguage as SupportedLanguage; } else { // Default to English if no language is found currentLang = 'en'; } } // Get translated header data - ensure we're using the current language const headerData = getHeaderData(currentLang); const { id = 'header', links = headerData.links, isSticky = false, isDark = false, isFullWidth = false, showToggleTheme = false, position = 'center', } = Astro.props; ---
{showToggleTheme && }