This plan is divided into three parts: first, we'll fix the build and content rendering; second, we'll reorganize the code and file structure; and third, we'll refactor the components for better modularity.
- Problem: The current setup uses a combination of a custom
remark-typora-mermaidplugin and a large, inefficient inline script inBaseLayout.astroto render Mermaid diagrams. This is complex and not standard. - Proposed Solution: We will adopt the official
astro-mermaidintegration for a simpler and more maintainable solution. - Implementation Steps:
- Install the
astro-mermaidpackage:npm install astro-mermaid mermaid. - Remove the
remark-typora-mermaidplugin fromastro.config.mjs. - Add the
astro-mermaidintegration toastro.config.mjs.import mermaid from 'astro-mermaid'; export default defineConfig({ integrations: [ mermaid({ // Options can be configured here }) ] });
- Delete the custom Mermaid rendering script from
BaseLayout.astro. - Verify that existing Mermaid diagrams in markdown files render correctly.
- Install the
- Problem:
BaseLayout.astrocontains redundant scripts for loading and rendering KaTeX, whileastro.config.mjsalready correctly configuresrehype-katex. This adds unnecessary client-side load. - Proposed Solution: Remove the redundant client-side scripts and rely on the server-side rendering provided by
rehype-katex. - Implementation Steps:
- In
BaseLayout.astro, remove the<script>tags that loadkatex.min.jsandauto-render.min.jsfrom the CDN. - Remove the inline
<script>that callsrenderMathInDocument(). - Confirm that the
remark-mathandrehype-katexplugins inastro.config.mjsare correctly configured. - Test a page with math formulas to ensure they are still rendering correctly.
- In
- Problem: Styles are scattered between global files, component-scoped styles, and a
custom-overrides.cssfile. - Proposed Solution: Centralize the core design system and remove redundant or misplaced style rules.
- Implementation Steps:
- Audit and Merge: Review the rules in
src/styles/custom-overrides.css. Move any truly global styles (e.g., typography, layout defaults) intosrc/styles/global.css. Move component-specific overrides into the<style>block of the relevant.astrocomponent. - Delete
custom-overrides.css: Once all its rules have been migrated, delete this file and remove its@importfromBaseLayout.astro. - Variable-Only Styles: Ensure that all style blocks only use CSS variables for colors, fonts, and spacing, and do not contain hardcoded values.
- Audit and Merge: Review the rules in
- Problem: Utility functions exist in both
/src/liband/src/utils. This is redundant. - Proposed Solution: Consolidate all utility functions into the
/src/utilsdirectory. - Implementation Steps:
- Move the contents of
src/lib/utils.tstosrc/utils/. - Delete the
src/libdirectory. - Update any import paths that were pointing to
/src/lib.
- Move the contents of
- Problem: There are duplicate files, such as
mermaid-renderer.jsin bothpublic/scriptsandsrc/scripts. - Proposed Solution: Remove the duplicated files and rely on a single source of truth.
- Implementation Steps:
- After migrating to
astro-mermaid, bothmermaid-renderer.jsfiles should be obsolete. I will delete bothpublic/scripts/mermaid-renderer.jsandsrc/scripts/mermaid-renderer.js. - Review the contents of the
publicdirectory and compare it withsrc/assets(if it exists) anddocsto identify and remove any other unnecessary duplicates.
- After migrating to
- Problem: Some components like
Navigation.astroandProjectTimeline.astrocould be more modular. - Proposed Solution: Break them down where appropriate.
- Implementation Steps:
Navigation.astro: This component is relatively simple now. The main improvement will be to ensure all its styles are self-contained and use the global CSS variables.ProjectTimeline.astro: I will analyze this component to see if it can be broken into smaller pieces, for example, aTimelineItem.astrocomponent.
- Problem: Common UI elements like cards and buttons are styled within larger components, leading to code duplication.
- Proposed Solution: Create a library of reusable UI components in
src/components/ui. - Implementation Steps:
- Card Component: Create a
Card.astrocomponent insrc/components/uithat provides a consistent wrapper with props fortitle,description, etc. - Button Component: The project already has a
button.tsxfile. I will investigate its usage and see if it can be used more consistently, or if a simpler.astrobutton component would be better. - Refactor existing pages: Replace the ad-hoc card and button styles in pages like
blog/index.astroandprojects/index.astrowith the new UI components.
- Card Component: Create a