From f8bf077948dcc1095b2d1f22d9c0d25120e18101 Mon Sep 17 00:00:00 2001 From: radishzzz Date: Tue, 4 Feb 2025 18:56:34 +0000 Subject: [PATCH] refactor: enhance theme configuration and path handling - Update config.ts with more descriptive comments and simplified settings - Remove about page content section - Add new path utility functions for localization and page type detection - Introduce SiteTitle component for mobile post page navigation - Modify Header and Layout components to use new path utilities - Adjust title spacing and font sizes - Update VSCode settings with new dictionary words --- .vscode/settings.json | 13 +++++++- src/components/Header.astro | 22 +++++++------ src/components/Navbar.astro | 45 +++------------------------ src/components/SiteTitle.astro | 15 +++++++++ src/config.ts | 50 ++++++++++------------------- src/layouts/Layout.astro | 13 ++++++-- src/types/index.d.ts | 8 +---- src/utils/path.ts | 57 ++++++++++++++++++++++++++++++++++ 8 files changed, 130 insertions(+), 93 deletions(-) create mode 100644 src/components/SiteTitle.astro create mode 100644 src/utils/path.ts diff --git a/.vscode/settings.json b/.vscode/settings.json index 9dfcebe..ccba829 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -62,13 +62,24 @@ "antfu", "astrojs", "attributify", + "bmoji", + "gtag", "katex", + "Lightbox", "mdast", + "msrc", + "msvalidate", "overlayscrollbars", "partytown", "photoswipe", + "pswp", + "radishzz", "rehype", + "Retypeset", + "Umami", "unocss", - "vite" + "vite", + "waline", + "weibo" ] } diff --git a/src/components/Header.astro b/src/components/Header.astro index fbca34c..54a7633 100644 --- a/src/components/Header.astro +++ b/src/components/Header.astro @@ -1,25 +1,29 @@ --- import themeConfig from '@/config' +import { getPagePath } from '@/utils/path' const { title, subtitle } = themeConfig.site const { titleSpace } = themeConfig.global +const currentPath = Astro.url.pathname +const { getLocalizedPath } = getPagePath(currentPath) const marginBottom = { 1: 'mb-1', - 2: 'mb-2', - 3: 'mb-3', - 4: 'mb-4', + 2: 'mb-3', + 3: 'mb-5', }[titleSpace] || 'mb-3' ---
-

- +

+ {title}

- -

- {subtitle} -

+ + {subtitle && ( +

+ {subtitle} +

+ )}
diff --git a/src/components/Navbar.astro b/src/components/Navbar.astro index 6d29278..e55ff45 100644 --- a/src/components/Navbar.astro +++ b/src/components/Navbar.astro @@ -1,49 +1,14 @@ --- -import themeConfig from '@/config' +import { getPagePath } from '@/utils/path' import { ui } from '@/utils/ui' -const defaultLocale = themeConfig.global.locale -const moreLocales = themeConfig.global.moreLocale const currentPath = Astro.url.pathname - -const cleanPath = (path: string) => path.replace(/^\/+|\/+$/g, '') - -function getLangFromPath(path: string) { - const secondaryLang = moreLocales.find(lang => - path.startsWith(`/${lang}/`) || path === `/${lang}` || path === `/${lang}/`, - ) - return secondaryLang || defaultLocale -} - -const currentLang = getLangFromPath(currentPath) +const { currentLang, isHome, isPost, isTag, isAbout, getLocalizedPath } = getPagePath(currentPath) const currentUI = ui[currentLang as keyof typeof ui] -function getLocalizedPath(path: string) { - const clean = cleanPath(path) - return currentLang === defaultLocale ? `/${clean}` : `/${currentLang}/${clean}` -} - -function isHomePage(path: string) { - const clean = cleanPath(path) - return clean === '' || moreLocales.includes(clean) -} -function isPostPage(path: string) { - const clean = cleanPath(path) - return clean.startsWith('posts') || moreLocales.some(lang => clean.startsWith(`${lang}/posts`)) -} -function isTagPage(path: string) { - const clean = cleanPath(path) - return clean.startsWith('tags') || moreLocales.some(lang => clean.startsWith(`${lang}/tags`)) -} -function isAboutPage(path: string) { - const clean = cleanPath(path) - return clean.startsWith('about') || moreLocales.some(lang => clean.startsWith(`${lang}/about`)) -} - -const isPostActive = isHomePage(currentPath) || isPostPage(currentPath) -const isTagActive = isTagPage(currentPath) -const isAboutActive = isAboutPage(currentPath) - +const isPostActive = isHome || isPost +const isTagActive = isTag +const isAboutActive = isAbout ---