Skip to content

Commit cb44ab4

Browse files
committed
fix: 对博客链接中的slug进行URI编码
修复博客链接中未对slug进行URI编码的问题,防止特殊字符导致链接失效
1 parent c0ec8b5 commit cb44ab4

3 files changed

Lines changed: 6 additions & 6 deletions

File tree

src/components/CopyrightNotice.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ export default function CopyrightNotice({
4040
}
4141

4242
const licenseInfo = getCCLicenseInfo(licenseType);
43-
const articleUrl = `${copyrightConfig.siteUrl}/blogs/${slug}`;
43+
const articleUrl = `${copyrightConfig.siteUrl}/blogs/${encodeURIComponent(slug)}`;
4444
const publishYear = new Date(publishDate).getFullYear();
4545

4646
// 判断是否需要折叠(超过3个引用)

src/components/archive/ClientArchivePage.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -377,8 +377,8 @@ export default function ClientArchivePage({ archivedPosts }: ClientArchivePagePr
377377
transition={{ duration: 0.4 }}
378378
className={getGlassStyle("p-4 rounded-lg border transition-all duration-300")}
379379
>
380-
<Link
381-
href={`/blogs/${post.slug}`}
380+
<Link
381+
href={`/blogs/${encodeURIComponent(post.slug)}`}
382382
className="block group"
383383
>
384384
<div className="flex items-center gap-2">
@@ -489,8 +489,8 @@ export default function ClientArchivePage({ archivedPosts }: ClientArchivePagePr
489489
transition={{ duration: 0.4, delay: Math.random() * 0.1 }}
490490
className="p-4 rounded-lg border border-border/50 hover:border-primary/30 transition-all duration-300"
491491
>
492-
<Link
493-
href={`/blogs/${post.slug}`}
492+
<Link
493+
href={`/blogs/${encodeURIComponent(post.slug)}`}
494494
className="block group"
495495
onClick={closeTagModal}
496496
>

src/components/moments/ClientMomentsPage.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ function ClientMomentsPage({ moments, blogCount, blogTotalWordCount, blogs, cate
150150
className="p-4 rounded-lg border transition-all duration-300 backdrop-blur-md bg-card/90 border-border shadow-md supports-[backdrop-filter]:bg-card/75"
151151
>
152152
<div className="text-foreground text-sm">
153-
<p>在【{blog.updatedAt || blog.date}】发布了<a href={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/blogs/${blog.id}`} className="text-primary hover:underline">{blog.title}</a></p>
153+
<p>在【{blog.updatedAt || blog.date}】发布了<a href={`${process.env.NEXT_PUBLIC_BASE_PATH || ''}/blogs/${encodeURIComponent(blog.id)}`} className="text-primary hover:underline">{blog.title}</a></p>
154154
</div>
155155
</div>
156156
);

0 commit comments

Comments
 (0)