From 5d3d7542525a5438794a9a0be79038cec379f8cd Mon Sep 17 00:00:00 2001 From: gbanyan Date: Wed, 19 Nov 2025 23:10:34 +0800 Subject: [PATCH] Fix tag URL encoding for non-ASCII characters MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Updated getTagSlug() to properly encode tags with spaces and non-ASCII characters (like Chinese). The function now: - Normalizes multiple spaces/dashes to single dashes - Properly encodes non-ASCII characters using encodeURIComponent - Prevents issues with URL encoding on Vercel deployment This fixes tags like "Medicine - 醫學" being displayed as "medicine---%E9%86%AB%E5%AD%B8" by generating clean URLs like "medicine-%E9%86%AB%E5%AD%B8". 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude --- lib/posts.ts | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/posts.ts b/lib/posts.ts index 7717833..9828894 100644 --- a/lib/posts.ts +++ b/lib/posts.ts @@ -27,7 +27,14 @@ export function getPageBySlug(slug: string): Page | undefined { } export function getTagSlug(tag: string): string { - return tag.toLowerCase().replace(/\s+/g, '-'); + // Normalize spaces and convert to lowercase first + // Replace multiple spaces/dashes with single dash + const normalized = tag + .toLowerCase() + .replace(/\s+/g, '-') + .replace(/-+/g, '-'); + // Encode URI components to handle non-ASCII characters properly + return encodeURIComponent(normalized); } export function getAllTagsWithCount(): { tag: string; slug: string; count: number }[] {