Skip to content

Commit 57c6ec6

Browse files
committed
refactor: 使用路径别名替换相对路径导入
为了提高代码的可维护性和可读性,将相对路径导入替换为路径别名。同时,更新了 `tsconfig.json` 以支持路径别名配置,并新增了博客页面。
1 parent e0916c2 commit 57c6ec6

7 files changed

Lines changed: 75 additions & 35 deletions

File tree

blog-web/src/components/Header.astro

Lines changed: 43 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
---
2-
import ScrollHeader from "../components/solid/ScrollHeader";
3-
import ThemeToggle from "../components/solid/ThemeToggle";
2+
import ScrollHeader from "@/components/solid/ScrollHeader";
3+
import ThemeToggle from "@/components/solid/ThemeToggle";
44
55
// Get current path to highlight active navigation item
66
const currentPath = Astro.url.pathname;
@@ -11,7 +11,7 @@ const isProjectsPage = currentPath.startsWith("/projects");
1111
1212
// Helper function to determine tab classes
1313
const getTabClass = (isActive: boolean) => {
14-
return isActive ? "tab tab-active" : "tab";
14+
return isActive ? "tab tab-active" : "tab";
1515
};
1616
---
1717

@@ -38,10 +38,35 @@ const getTabClass = (isActive: boolean) => {
3838
tabindex="0"
3939
class="menu menu-sm dropdown-content mt-3 z-[1] p-2 shadow bg-base-100 rounded-box w-52"
4040
>
41-
<li><a href="/" class={isHomePage ? "font-bold text-primary" : ""}>首页</a></li>
42-
<li><a href="/blog" class={isBlogPage ? "font-bold text-primary" : ""}>博客</a></li>
43-
<li><a href="/about" class={isAboutPage ? "font-bold text-primary" : ""}>关于我</a></li>
44-
<li><a href="/projects" class={isProjectsPage ? "font-bold text-primary" : ""}>项目</a></li>
41+
<li>
42+
<a
43+
href="/"
44+
class={isHomePage ? "font-bold text-primary" : ""}
45+
>首页</a
46+
>
47+
</li>
48+
<li>
49+
<a
50+
href="/blog"
51+
class={isBlogPage ? "font-bold text-primary" : ""}
52+
>博客</a
53+
>
54+
</li>
55+
<li>
56+
<a
57+
href="/about"
58+
class={isAboutPage ? "font-bold text-primary" : ""}
59+
>关于我</a
60+
>
61+
</li>
62+
<li>
63+
<a
64+
href="/projects"
65+
class={isProjectsPage
66+
? "font-bold text-primary"
67+
: ""}>项目</a
68+
>
69+
</li>
4570
</ul>
4671
</div>
4772
<a href="/" class="btn btn-ghost text-xl">
@@ -51,9 +76,17 @@ const getTabClass = (isActive: boolean) => {
5176
<div class="navbar-center hidden lg:flex">
5277
<div role="tablist" class="tabs tabs-bordered">
5378
<a href="/" role="tab" class={getTabClass(isHomePage)}>首页</a>
54-
<a href="/blog" role="tab" class={getTabClass(isBlogPage)}>博客</a>
55-
<a href="/about" role="tab" class={getTabClass(isAboutPage)}>关于我</a>
56-
<a href="/projects" role="tab" class={getTabClass(isProjectsPage)}>项目</a>
79+
<a href="/blog" role="tab" class={getTabClass(isBlogPage)}
80+
>博客</a
81+
>
82+
<a href="/about" role="tab" class={getTabClass(isAboutPage)}
83+
>关于我</a
84+
>
85+
<a
86+
href="/projects"
87+
role="tab"
88+
class={getTabClass(isProjectsPage)}>项目</a
89+
>
5790
</div>
5891
</div>
5992
<div class="navbar-end">

blog-web/src/layouts/Layout.astro

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
---
2-
import "../styles/global.css";
3-
import background from "../assets/background.svg";
4-
import Header from "../components/Header.astro";
5-
import Footer from "../components/Footer.astro";
2+
import "@/styles/global.css";
3+
import background from "@/assets/background.svg";
4+
import Header from "@/components/Header.astro";
5+
import Footer from "@/components/Footer.astro";
66
77
interface Props {
88
title?: string;
@@ -22,19 +22,27 @@ const { title = "My Blog" } = Astro.props;
2222
<script is:inline>
2323
// Apply saved theme immediately to prevent flash
2424
try {
25-
const savedTheme = localStorage.getItem('theme');
25+
const savedTheme = localStorage.getItem("theme");
2626
if (savedTheme) {
27-
document.documentElement.setAttribute('data-theme', savedTheme);
28-
} else if (window.matchMedia('(prefers-color-scheme: dark)').matches) {
29-
document.documentElement.setAttribute('data-theme', 'dark');
30-
localStorage.setItem('theme', 'dark');
27+
document.documentElement.setAttribute(
28+
"data-theme",
29+
savedTheme,
30+
);
31+
} else if (
32+
window.matchMedia("(prefers-color-scheme: dark)").matches
33+
) {
34+
document.documentElement.setAttribute("data-theme", "dark");
35+
localStorage.setItem("theme", "dark");
3136
} else {
32-
document.documentElement.setAttribute('data-theme', 'light');
33-
localStorage.setItem('theme', 'light');
37+
document.documentElement.setAttribute(
38+
"data-theme",
39+
"light",
40+
);
41+
localStorage.setItem("theme", "light");
3442
}
3543
} catch (e) {
3644
// Fallback for environments where localStorage is not available
37-
document.documentElement.setAttribute('data-theme', 'light');
45+
document.documentElement.setAttribute("data-theme", "light");
3846
}
3947
</script>
4048
</head>

blog-web/src/pages/about.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import Layout from "../layouts/Layout.astro";
2+
import Layout from "@/layouts/Layout.astro";
33
---
44

55
<Layout title="关于我 | ExquisiteCore - 精致的私人博客">
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import Layout from "../layouts/Layout.astro";
2+
import Layout from "@/layouts/Layout.astro";
33
---
44

55
<Layout title="博客 | 精致的芯 - 精致的私人博客">

blog-web/src/pages/index.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import Layout from "../layouts/Layout.astro";
2+
import Layout from "@/layouts/Layout.astro";
33
---
44

55
<Layout title="ExquisiteCore - 个人博客">

blog-web/src/pages/projects.astro

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
import Layout from "../layouts/Layout.astro";
2+
import Layout from "@/layouts/Layout.astro";
33
---
44

55
<Layout title="项目 | 精致的芯 - 精致的私人博客">

blog-web/tsconfig.json

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
11
{
22
"extends": "astro/tsconfigs/strict",
3-
"include": [
4-
".astro/types.d.ts",
5-
"**/*"
6-
],
7-
"exclude": [
8-
"dist"
9-
],
3+
"include": [".astro/types.d.ts", "**/*"],
4+
"exclude": ["dist"],
105
"compilerOptions": {
116
"jsx": "preserve",
12-
"jsxImportSource": "solid-js"
7+
"jsxImportSource": "solid-js",
8+
"baseUrl": ".",
9+
"paths": {
10+
"@/*": ["src/*"]
11+
}
1312
}
14-
}
13+
}

0 commit comments

Comments
 (0)