From c23a54ae8385d95181311c52b90e935bf433a286 Mon Sep 17 00:00:00 2001 From: radishzzz Date: Wed, 12 Mar 2025 01:05:15 +0000 Subject: [PATCH] refactor: clean up configuration and components, optimize implementation details - Remove unused navigation bar and social link configurations - Update Footer component, simplify code - Refactor PostList and PostTime components, improve code readability - Adjust Waline comment component styles - Streamline content config and reading time plugin - Update theme guide document titles and tags --- pnpm-lock.yaml | 22 ++++---- src/components/Comments/Waline.astro | 2 +- src/components/DateFormat.astro | 78 ---------------------------- src/components/Footer.astro | 1 - src/components/PostList.astro | 19 +++---- src/components/PostTime.astro | 7 ++- src/config.ts | 21 ++------ src/content/config.ts | 3 +- src/content/posts/Theme Guide-zh.mdx | 4 +- src/plugins/remark-reading-time.js | 2 - 10 files changed, 33 insertions(+), 126 deletions(-) delete mode 100644 src/components/DateFormat.astro diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index d5b1900..756e888 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -268,13 +268,13 @@ packages: resolution: {integrity: sha512-Ed61U6XJc3CVRfkERJWDz4dJwKe7iLmmJsbOGu9wSloNSFttHV0I8g6UAgb7qnK5ly5bGLPd4oXZlxCdANBOWQ==} engines: {node: '>=6.9.0'} - '@babel/parser@7.26.9': - resolution: {integrity: sha512-81NWa1njQblgZbQHxWHpxxCzNsa3ZwvFqpUg7P+NNUU6f3UU2jBEg4OlF/J6rl8+PQGh1q6/zWScd001YwcA5A==} + '@babel/parser@7.26.10': + resolution: {integrity: sha512-6aQR2zGE/QFi8JpDLjUZEPYOs7+mhKXm86VaKFiLP35JQwQb6bwUE+XbvkH0EptsYhbNBSUGaUBLKqxH1xSgsA==} engines: {node: '>=6.0.0'} hasBin: true - '@babel/types@7.26.9': - resolution: {integrity: sha512-Y3IR1cRnOxOCDvMmNiym7XpXQ93iGDDPHx+Zj+NM+rg0fBaShfQLkg+hKPaZCEvg5N/LeCo4+Rj/i3FuJsIQaw==} + '@babel/types@7.26.10': + resolution: {integrity: sha512-emqcG3vHrpxUKTrxcblR36dcrcoRDvKmnL/dCL6ZsHaShW80qxCAcNhzQZrpeM765VzEos+xOi4s+r4IXzTwdQ==} engines: {node: '>=6.9.0'} '@clack/core@0.4.1': @@ -3941,11 +3941,11 @@ snapshots: '@babel/helper-validator-identifier@7.25.9': {} - '@babel/parser@7.26.9': + '@babel/parser@7.26.10': dependencies: - '@babel/types': 7.26.9 + '@babel/types': 7.26.10 - '@babel/types@7.26.9': + '@babel/types@7.26.10': dependencies: '@babel/helper-string-parser': 7.25.9 '@babel/helper-validator-identifier': 7.25.9 @@ -4841,7 +4841,7 @@ snapshots: '@vue/compiler-core@3.5.13': dependencies: - '@babel/parser': 7.26.9 + '@babel/parser': 7.26.10 '@vue/shared': 3.5.13 entities: 4.5.0 estree-walker: 2.0.2 @@ -4854,7 +4854,7 @@ snapshots: '@vue/compiler-sfc@3.5.13': dependencies: - '@babel/parser': 7.26.9 + '@babel/parser': 7.26.10 '@vue/compiler-core': 3.5.13 '@vue/compiler-dom': 3.5.13 '@vue/compiler-ssr': 3.5.13 @@ -6403,8 +6403,8 @@ snapshots: magicast@0.3.5: dependencies: - '@babel/parser': 7.26.9 - '@babel/types': 7.26.9 + '@babel/parser': 7.26.10 + '@babel/types': 7.26.10 source-map-js: 1.2.1 markdown-extensions@2.0.0: {} diff --git a/src/components/Comments/Waline.astro b/src/components/Comments/Waline.astro index 0773fe2..3005141 100644 --- a/src/components/Comments/Waline.astro +++ b/src/components/Comments/Waline.astro @@ -146,7 +146,7 @@ document.addEventListener('astro:after-swap', initWaline) } #waline .wl-content p { - --at-apply: 'leading-6'; + --at-apply: 'leading-6 text-3.5'; } #waline .wl-time { diff --git a/src/components/DateFormat.astro b/src/components/DateFormat.astro deleted file mode 100644 index ae6590d..0000000 --- a/src/components/DateFormat.astro +++ /dev/null @@ -1,78 +0,0 @@ ---- -import { themeConfig } from '@/config' -import { isPostPage } from '@/utils/path' - -interface Props { - date: Date - updatedDate?: Date - minutes?: number -} - -const { date, updatedDate, minutes } = Astro.props -const format = themeConfig.global.dateFormat -const currentPath = Astro.url.pathname -const isPost = isPostPage(currentPath) -const updatedTimeMarginClass = isPost ? 'ml-1.75' : 'ml-1.5' -const readingTimeMarginClass = isPost ? 'ml-1.75' : 'ml-1.5' - -function formatDate(date: Date, format: 'YYYY-MM-DD' | 'MM-DD-YYYY' | 'DD-MM-YYYY' | 'MONTH DAY YYYY' | 'DAY MONTH YYYY') { - const options: Intl.DateTimeFormatOptions = { - year: 'numeric', - month: format === 'MONTH DAY YYYY' || format === 'DAY MONTH YYYY' ? 'short' : '2-digit', - day: format === 'MONTH DAY YYYY' || format === 'DAY MONTH YYYY' ? 'numeric' : '2-digit', - } - - switch (format) { - // ISO format: 2024-03-04 - case 'YYYY-MM-DD': - return date.toISOString().split('T')[0] - - // US date format: 03-04-2024 - case 'MM-DD-YYYY': - return date.toLocaleDateString('en-US', options).replace(/\//g, '-') - - // European date format: 04-03-2024 - case 'DD-MM-YYYY': - return date.toLocaleDateString('en-GB', options).replace(/\//g, '-') - - // US month text format: Mar 4 2024 - case 'MONTH DAY YYYY': - return date.toLocaleDateString('en-US', { - year: 'numeric', - month: 'short', - day: 'numeric', - }).replace(',', '') - - // British month text format: 4 Mar 2024 - case 'DAY MONTH YYYY': - return date.toLocaleDateString('en-GB', { - year: 'numeric', - month: 'short', - day: 'numeric', - }).replace(',', '') - - // Default to ISO format - default: - return date.toISOString().split('T')[0] - } -} ---- - - - - - -{updatedDate && ( - -)} - - -{minutes !== undefined && ( - - {minutes} min - -)} diff --git a/src/components/Footer.astro b/src/components/Footer.astro index 345ced8..c78dd83 100644 --- a/src/components/Footer.astro +++ b/src/components/Footer.astro @@ -6,7 +6,6 @@ interface Props { } const { class: className } = Astro.props - const { author } = themeConfig.site const { links, startYear } = themeConfig.footer diff --git a/src/components/PostList.astro b/src/components/PostList.astro index a643282..51cf545 100644 --- a/src/components/PostList.astro +++ b/src/components/PostList.astro @@ -6,28 +6,29 @@ interface Post { title: string abbrlink?: string published: Date - lang?: string } + // URL path automatically generated by Astro based on the filename slug?: string + // Optional for robustness in case render() fails or plugin isn't applied remarkPluginFrontmatter?: { minutes?: number } } -// Receive posts parameter passed from outside -const { posts, lang: pageLang } = Astro.props +// Get post list and page language parameter from props +const { posts, lang } = Astro.props -// Declare the type of props export interface Props { posts: Post[] lang?: string } -// 构建正确的链接路径 -function getPostUrl(post: Post) { +// Get multilingual post URL path +function getPostPath(post: Post) { + // If abbrlink is set, it will be used instead of slug const postPath = post.data.abbrlink || post.slug - // 如果是在语言文件夹下的页面,添加语言前缀 - return pageLang ? `/${pageLang}/posts/${postPath}/` : `/posts/${postPath}/` + // Add language prefix to URL if current page is in a language subdirectory + return lang ? `/${lang}/posts/${postPath}/` : `/posts/${postPath}/` } ---