From 83b765a398164c4c543128ff79fda0e91b0a932c Mon Sep 17 00:00:00 2001 From: saicaca Date: Fri, 6 Oct 2023 03:06:21 +0800 Subject: [PATCH] fix: make tag sorting case-insensitive, fix wrong url (cherry picked from commit 869eea036103abfcaec271d4f02c7ac2a8203648) --- src/utils/content-utils.ts | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/src/utils/content-utils.ts b/src/utils/content-utils.ts index fb173a5..a545137 100644 --- a/src/utils/content-utils.ts +++ b/src/utils/content-utils.ts @@ -20,7 +20,9 @@ export async function getSortedPosts() { return sorted; } -export function getPostUrlBySlug(slug: string): string { +export function getPostUrlBySlug(slug: string): string | null { + if (!slug) + return null; return `/posts/${slug}`; } @@ -35,9 +37,18 @@ export async function getTagList(): Promise<{ name: string; count: number }[]> { }) }); - // 获取对象的所有键并按字典顺序排序 - const keys: string[] = Object.keys(countMap).sort(); + // sort tags + const keys: string[] = Object.keys(countMap).sort(function (a, b) { + var textA = a.toLowerCase(); + var textB = b.toLowerCase(); + if (textA < textB) { + return -1; + } + if (textA > textB) { + return 1; + } + return 0; + }); - // 使用排序后的键构建包含 key 和 value 的数组 return keys.map((key) => ({name: key, count: countMap[key]})); }