From ee35006f7cdfd4daacdc113cb613f071c4ee037d Mon Sep 17 00:00:00 2001 From: radishzzz Date: Fri, 24 Jan 2025 13:23:24 +0000 Subject: [PATCH] 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. --- src/components/LanguageSwitcher.astro | 2 -- src/components/PhotoSwipe.astro | 12 ++++++------ src/config/index.ts | 10 +++++----- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/src/components/LanguageSwitcher.astro b/src/components/LanguageSwitcher.astro index cba2885..14d5173 100644 --- a/src/components/LanguageSwitcher.astro +++ b/src/components/LanguageSwitcher.astro @@ -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}` }) diff --git a/src/components/PhotoSwipe.astro b/src/components/PhotoSwipe.astro index fce58d3..c18e8c6 100644 --- a/src/components/PhotoSwipe.astro +++ b/src/components/PhotoSwipe.astro @@ -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) - + diff --git a/src/config/index.ts b/src/config/index.ts index 30db19b..5794a47 100644 --- a/src/config/index.ts +++ b/src/config/index.ts @@ -5,9 +5,9 @@ export const themeConfig: ThemeConfig = { site: { title: 'Retypeset', subtitle: '再现版式之美', - description: '一个优美的博客主题', + description: '重新编排 - 再现版式之美 | Retypeset - Rediscover the beauty of typography', author: 'radishzz', - url: 'https://retypeset.netlify.app', + url: 'https://retypeset.radishzz.cc', favicon: '/image/logo.svg', // or https://image.example.com/logo.svg. Support only webp, svg, png }, // SITE INFORMATION >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END @@ -32,10 +32,10 @@ export const themeConfig: ThemeConfig = { // GLOBAL SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> START global: { - locale: 'zh', // Support only zh, zh-tw, ja, en, es, ru. Default locale setting + locale: 'zh', // support only zh, zh-tw, ja, en, es, ru. Default locale setting moreLocale: ['zh-tw', 'ja', 'en', 'es', 'ru'], // ['zh', 'zh-tw', 'ja', 'en', 'es', 'ru']. NOT fill in the default locale code again - font: 'sans', // Support only sans, serif. Choose the font style for posts - titleSpace: 4, // Support only 1, 2, 3, 4. Space between title and subtitle, 1 is the smallest, 4 is the largest + font: 'sans', // support only sans, serif. Choose the font style for posts + titleSpace: 4, // support only 1, 2, 3, 4. Space between title and subtitle, 1 is the smallest, 4 is the largest }, // GLOBAL SETTINGS >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> END