mirror of
https://github.com/reonokiy/blog.nokiy.net.git
synced 2025-06-17 03:56:19 +02:00
refactor: enhance LanguageSwitcher and PhotoSwipe initialization
- Simplified LanguageSwitcher logic for better readability and performance. - Updated PhotoSwipe initialization to clean up existing instances before creating a new one, ensuring smoother transitions. - Changed event listener for PhotoSwipe to trigger on page load, improving responsiveness. - Revised theme configuration description and updated site URL for clarity.
This commit is contained in:
parent
bca8b9b1cf
commit
ee35006f7c
3 changed files with 11 additions and 13 deletions
|
@ -35,11 +35,9 @@ document.addEventListener('astro:page-load', () => {
|
|||
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}`
|
||||
})
|
||||
|
|
|
@ -8,6 +8,9 @@
|
|||
|
||||
// Initialize PhotoSwipe lightbox with custom configuration
|
||||
function createPhotoSwipe() {
|
||||
// Clean up existing instance if any
|
||||
cleanup()
|
||||
|
||||
lightbox = new PhotoSwipeLightbox({
|
||||
gallery: 'article img',
|
||||
pswpModule: () => pswp,
|
||||
|
@ -43,10 +46,7 @@
|
|||
}
|
||||
}
|
||||
|
||||
// Initialize PhotoSwipe when DOM is ready
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
createPhotoSwipe()
|
||||
})
|
||||
|
||||
// Initialize PhotoSwipe when DOM is ready and after page transitions
|
||||
document.addEventListener('astro:page-load', createPhotoSwipe)
|
||||
document.addEventListener('astro:before-swap', cleanup)
|
||||
</script>
|
||||
</script>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue