From 094351e3aeec49bd4bc7dd17c282ecf7388660cd Mon Sep 17 00:00:00 2001 From: the3ash <24548223+the3ash@users.noreply.github.com> Date: Sat, 12 Jul 2025 23:26:33 +0800 Subject: [PATCH] refactor: restructure config system with improved type safety --- astro.config.ts | 8 +- src/components/features/FormattedDate.astro | 7 +- src/components/features/PostList.astro | 10 +- src/components/layout/BaseHead.astro | 28 ++++- src/components/layout/Footer.astro | 4 +- src/components/layout/Header.astro | 6 +- src/components/layout/TransitionWrapper.astro | 4 +- src/components/ui/BackButton.astro | 14 ++- src/components/ui/CopyCode.astro | 6 +- src/components/ui/ImageOptimizer.astro | 100 ++++++++++++++++++ src/components/ui/TableOfContents.astro | 62 +++++------ src/components/ui/ThemeToggle.astro | 4 +- src/config.ts | 48 +++++---- src/content/config.ts | 13 --- src/content/posts/theme-guide.md | 38 +++++-- src/layouts/BaseLayout.astro | 17 +-- src/layouts/IndexLayout.astro | 4 +- src/layouts/PostLayout.astro | 22 ++-- src/pages/404.astro | 4 +- src/pages/index.astro | 4 +- src/plugins/rehype-image-processor.mjs | 12 ++- src/styles/global.css | 11 +- src/styles/post.css | 45 +++++++- src/types/component.types.ts | 15 +++ src/types/config.types.ts | 27 ++++- src/utils/date.ts | 6 +- src/utils/draft.ts | 2 +- src/utils/feed.ts | 14 +-- src/utils/image-config.ts | 27 +++++ 29 files changed, 416 insertions(+), 146 deletions(-) create mode 100644 src/components/ui/ImageOptimizer.astro delete mode 100644 src/content/config.ts create mode 100644 src/utils/image-config.ts diff --git a/astro.config.ts b/astro.config.ts index 18874fe..915d8f0 100644 --- a/astro.config.ts +++ b/astro.config.ts @@ -10,11 +10,12 @@ import rehypeCleanup from './src/plugins/rehype-cleanup.mjs' import rehypeImageProcessor from './src/plugins/rehype-image-processor.mjs' import rehypeCopyCode from './src/plugins/rehype-copy-code.mjs' import remarkTOC from './src/plugins/remark-toc.mjs' -import { SITE } from './src/config' +import { themeConfig } from './src/config' +import { imageConfig } from './src/utils/image-config' import path from 'path' export default defineConfig({ - site: SITE.website, + site: themeConfig.site.website, devToolbar: { enabled: false }, @@ -24,7 +25,8 @@ export default defineConfig({ }, image: { service: { - entrypoint: 'astro/assets/services/sharp' + entrypoint: 'astro/assets/services/sharp', + config: imageConfig } }, markdown: { diff --git a/src/components/features/FormattedDate.astro b/src/components/features/FormattedDate.astro index 6aec9d6..66185ab 100644 --- a/src/components/features/FormattedDate.astro +++ b/src/components/features/FormattedDate.astro @@ -1,6 +1,6 @@ --- +import { themeConfig } from '@/config' import { formatDate } from '@/utils/date' -import { SITE } from '@/config' interface Props { date: Date @@ -12,8 +12,9 @@ const { date, format } = Astro.props