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
This commit is contained in:
radishzzz 2025-02-04 18:56:34 +00:00
parent 35b2542ec8
commit f8bf077948
8 changed files with 130 additions and 93 deletions

View file

@ -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'
---
<header>
<h1 class={`${marginBottom} mt--5.2 text-12 c-primary font-bold font-title`}>
<a href="/">
<h1 class={`${marginBottom} mt--5 text-12.8 c-primary font-bold font-title`}>
<a href={getLocalizedPath('/')}>
{title}
</a>
</h1>
<h2 class="text-5.6 c-secondary font-navbar">
{subtitle}
</h2>
{subtitle && (
<h2 class="text-5.6 c-secondary font-navbar">
{subtitle}
</h2>
)}
</header>

View file

@ -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
---
<nav class="mb-16 mt-13 text-5.6 font-semibold leading-13 font-navbar">

View file

@ -0,0 +1,15 @@
---
import themeConfig from '@/config'
import { getPagePath } from '@/utils/path'
const { title } = themeConfig.site
const currentPath = Astro.url.pathname
const { getLocalizedPath } = getPagePath(currentPath)
---
<a
class="mt--1.4 text-8.32 c-secondary font-bold font-title"
href={getLocalizedPath('/')}
>
{title}
</a>