mirror of
https://github.com/KazooTTT/kazoottt-blog.git
synced 2025-06-22 02:01:32 +08:00
feat: add category page
This commit is contained in:
@ -37,3 +37,26 @@ export function getUniqueTagsWithCount(
|
||||
)
|
||||
].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'>>) {
|
||||
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