Skip to content

Commit 496c458

Browse files
committed
fix: use withBase() for all internal links to support /blog/ base path
1 parent b10a7de commit 496c458

2 files changed

Lines changed: 8 additions & 7 deletions

File tree

docs/.vitepress/theme/ArchiveYear.vue

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<script setup lang="ts">
22
import { data as allPosts } from "../../posts.data";
33
import { computed } from "vue";
4-
import { useRoute } from "vitepress";
4+
import { useRoute, withBase } from "vitepress";
55
66
const route = useRoute();
77
@@ -59,20 +59,20 @@ function formatDate(d: string) {
5959
<ul class="posts-in-month">
6060
<li v-for="post in group.posts" :key="post.url" class="post-item">
6161
<time class="post-date">{{ formatDate(post.date) }}</time>
62-
<a :href="post.url" class="post-title">{{ post.title }}</a>
62+
<a :href="withBase(post.url)" class="post-title">{{ post.title }}</a>
6363
</li>
6464
</ul>
6565
</div>
6666
</div>
6767

6868
<div class="archive-nav">
69-
<a href="/archive/" class="nav-link">← 返回归档</a>
70-
<a href="/posts/" class="nav-link">查看所有文章 →</a>
69+
<a :href="withBase('/archive/')" class="nav-link">← 返回归档</a>
70+
<a :href="withBase('/posts/')" class="nav-link">查看所有文章 →</a>
7171
</div>
7272
</div>
7373
<div v-else class="no-posts">
7474
<p>{{ year ? `${year} 年没有文章` : "获取年份失败" }}</p>
75-
<a href="/archive/">返回归档 →</a>
75+
<a :href="withBase('/archive/')">返回归档 →</a>
7676
</div>
7777
</template>
7878

docs/.vitepress/theme/PostList.vue

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
<script setup lang="ts">
22
import { data as allPosts } from "../../posts.data";
33
import { ref, computed, watch } from "vue";
4+
import { withBase } from "vitepress";
45
56
interface Category {
67
id: string;
@@ -195,7 +196,7 @@ const archiveLinks = (() => {
195196
const maxMonth = y === 2025 ? 12 : 12;
196197
const months = Array.from({ length: maxMonth }, (_, i) => ({
197198
label: `${i + 1}月`,
198-
path: `/archive/${y}/${String(i + 1).padStart(2, "0")}/`,
199+
path: withBase(`/archive/${y}/${String(i + 1).padStart(2, "0")}/`),
199200
}));
200201
result.push({ year: String(y), months });
201202
}
@@ -265,7 +266,7 @@ const archiveLinks = (() => {
265266
<ul class="article-list">
266267
<li v-for="post in pagedPosts" :key="post.url" class="article-item">
267268
<time class="article-date">{{ formatDate(post.date) }}</time>
268-
<a :href="post.url" class="article-title">{{ post.title }}</a>
269+
<a :href="withBase(post.url)" class="article-title">{{ post.title }}</a>
269270
</li>
270271
<li v-if="pagedPosts.length === 0" class="no-results">
271272
没有找到匹配的文章

0 commit comments

Comments
 (0)