mirror of
https://github.com/KazooTTT/kazoottt-blog-v2.git
synced 2025-06-24 19:21:31 +08:00
feat: 新增分类
This commit is contained in:
@ -55,3 +55,25 @@ export function getUniqueTagsWithCount(posts: CollectionEntry<"post">[]): [strin
|
||||
),
|
||||
].sort((a, b) => b[1] - a[1]);
|
||||
}
|
||||
|
||||
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
|
||||
export function getAllCategories(posts: Array<CollectionEntry<"post">>): string[] {
|
||||
return posts.map((post) => post.data.category ?? "未分类");
|
||||
}
|
||||
|
||||
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
|
||||
export function getUniqueCategories(posts: Array<CollectionEntry<"post">>): string[] {
|
||||
return [...new Set(getAllCategories(posts))];
|
||||
}
|
||||
|
||||
/** Note: This function doesn't filter draft posts, pass it the result of getAllPosts above to do so. */
|
||||
export function getUniqueCategoriesWithCount(
|
||||
posts: Array<CollectionEntry<"post">>,
|
||||
): Array<[string, number]> {
|
||||
return [
|
||||
...getAllCategories(posts).reduce(
|
||||
(acc, t) => acc.set(t, (acc.get(t) || 0) + 1),
|
||||
new Map<string, number>(),
|
||||
),
|
||||
].sort((a, b) => b[1] - a[1]);
|
||||
}
|
||||
|
Reference in New Issue
Block a user