diff --git a/src/components/LanguageSwitcher.astro b/src/components/LanguageSwitcher.astro index 4fb3ea8..e849e4e 100644 --- a/src/components/LanguageSwitcher.astro +++ b/src/components/LanguageSwitcher.astro @@ -55,7 +55,6 @@ function buildNewPath(currentLang, nextLang, segments, pathname) { if (currentLang) { segments[0] = nextLang || segments[0] - // Handle path with or without language code return nextLang ? `/${segments.join('/')}` : `/${segments.slice(1).join('/')}` diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro index fa1bc69..23b5b76 100644 --- a/src/components/Navbar.astro +++ b/src/components/Navbar.astro @@ -2,15 +2,12 @@ import themeConfig from '@/config' import { ui } from '@/utils/ui' -// Configuration const defaultLocale = themeConfig.global.locale const moreLocales = themeConfig.global.moreLocale const currentPath = Astro.url.pathname -// Path utilities const cleanPath = (path: string) => path.replace(/^\/+|\/+$/g, '') -// Language utilities function getLangFromPath(path: string) { const secondaryLang = moreLocales.find(lang => path.startsWith(`/${lang}/`) || path === `/${lang}` || path === `/${lang}/`, @@ -21,13 +18,11 @@ function getLangFromPath(path: string) { const currentLang = getLangFromPath(currentPath) const currentUI = ui[currentLang as keyof typeof ui] -// Localization utilities function getLocalizedPath(path: string) { const clean = cleanPath(path) return currentLang === defaultLocale ? `/${clean}` : `/${currentLang}/${clean}` } -// Page type detection utilities function isHomePage(path: string) { const clean = cleanPath(path) return clean === '' || moreLocales.includes(clean) @@ -45,7 +40,6 @@ function isAboutPage(path: string) { return clean.startsWith('about') || moreLocales.some(lang => clean.startsWith(`${lang}/about`)) } -// Active state detection const isPostActive = isHomePage(currentPath) || isPostPage(currentPath) const isTagActive = isTagPage(currentPath) const isAboutActive = isAboutPage(currentPath) diff --git a/src/components/PhotoSwipe.astro b/src/components/PhotoSwipe.astro index c18e8c6..e2b1b8d 100644 --- a/src/components/PhotoSwipe.astro +++ b/src/components/PhotoSwipe.astro @@ -2,11 +2,16 @@ import PhotoSwipeLightbox from 'photoswipe/lightbox' import 'photoswipe/style.css' - // Store lightbox instance for later use let lightbox: PhotoSwipeLightbox | null = null const pswp = import('photoswipe') - // Initialize PhotoSwipe lightbox with custom configuration + function cleanup() { + if (lightbox) { + lightbox.destroy() + lightbox = null + } + } + function createPhotoSwipe() { // Clean up existing instance if any cleanup() @@ -24,7 +29,7 @@ doubleTapAction: 'zoom', }) - // Add custom filter to handle image data and dimensions + // Automatically add image dimensions lightbox.addFilter('domItemData', (itemData: any, element: Element) => { if (element instanceof HTMLImageElement) { itemData.src = element.src @@ -38,15 +43,6 @@ lightbox.init() } - // Cleanup function to destroy lightbox instance - function cleanup() { - if (lightbox) { - lightbox.destroy() - lightbox = null - } - } - - // Initialize PhotoSwipe when DOM is ready and after page transitions document.addEventListener('astro:page-load', createPhotoSwipe) document.addEventListener('astro:before-swap', cleanup) diff --git a/src/components/Scrollbar.astro b/src/components/Scrollbar.astro index 845128b..12c8e14 100644 --- a/src/components/Scrollbar.astro +++ b/src/components/Scrollbar.astro @@ -1,10 +1,8 @@