mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-17 20:01:33 +02:00
refactor: restructure project configuration and utility modules
- Move configuration and utility files to more organized locations - Update import paths across the project to reflect new file structure - Simplify content and internationalization utilities - Remove redundant configuration files and consolidate logic - Add prefetch configuration to Astro config for improved performance
This commit is contained in:
parent
a26031d490
commit
fc1daf4335
23 changed files with 380 additions and 393 deletions
|
@ -1,56 +0,0 @@
|
|||
---
|
||||
import themeConfig from '@/config'
|
||||
|
||||
// Language array with empty string as default locale
|
||||
const langs = ['', ...themeConfig.global.moreLocale]
|
||||
const currentLocale = themeConfig.global.locale
|
||||
|
||||
function getLanguageDisplayName(code: string) {
|
||||
if (!code)
|
||||
return 'Default'
|
||||
return new Intl.DisplayNames(['en'], { type: 'language' }).of(code) || code
|
||||
}
|
||||
---
|
||||
|
||||
<button
|
||||
id="language-switcher"
|
||||
class="absolute right-25.6 top-20 z-99 aspect-square w-6.6 c-secondary active:scale-92"
|
||||
aria-label="Switch Language"
|
||||
title={`Current Language: ${getLanguageDisplayName(currentLocale)}`}
|
||||
>
|
||||
<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" class="h-full w-full">
|
||||
<path d="M19 21 12.3 2h-1L4.7 21l-2.5.2v.8h6.3v-.8L5.7 21l2-5.9h7.5l2 5.9-3.3.2v.8h7.9v-.8zM8 14.3l3.4-10.1 3.5 10.1z" fill="currentColor" />
|
||||
</svg>
|
||||
<span class="sr-only">Switch Language</span>
|
||||
</button>
|
||||
|
||||
<script is:inline define:vars={{ langs }}>
|
||||
// Move event binding into astro:page-load event
|
||||
document.addEventListener('astro:page-load', () => {
|
||||
const langSwitch = document.getElementById('language-switcher')
|
||||
|
||||
langSwitch?.addEventListener('click', () => {
|
||||
const { pathname, search, hash } = window.location
|
||||
const segments = pathname.split('/').filter(Boolean)
|
||||
const firstSegment = segments[0] || ''
|
||||
// Check if first segment is a valid language code
|
||||
const currentLang = langs.includes(firstSegment) ? firstSegment : ''
|
||||
// Get next language in rotation (empty string means default locale)
|
||||
const currentIndex = langs.indexOf(currentLang)
|
||||
const nextLang = langs[(currentIndex + 1) % langs.length]
|
||||
const newPath = buildNewPath(currentLang, nextLang, segments, pathname) || '/'
|
||||
window.location.href = `${newPath}${search}${hash}`
|
||||
})
|
||||
})
|
||||
|
||||
// Handle path construction for both cases:
|
||||
// 1. Current path has language prefix
|
||||
// 2. Current path has no language prefix
|
||||
function buildNewPath(currentLang, nextLang, segments, pathname) {
|
||||
if (currentLang) {
|
||||
segments[0] = nextLang || segments[0]
|
||||
return nextLang ? `/${segments.join('/')}` : `/${segments.slice(1).join('/')}`
|
||||
}
|
||||
return nextLang ? `/${nextLang}${pathname}` : pathname
|
||||
}
|
||||
</script>
|
Loading…
Add table
Add a link
Reference in a new issue