mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-06-07 23:16:52 +00:00
NEXT主题,分类标签调整
This commit is contained in:
@@ -3,11 +3,11 @@
|
||||
* @param allPosts
|
||||
* @returns {Promise<{}|*[]>}
|
||||
*/
|
||||
export async function getAllCategories (allPosts) {
|
||||
if (!allPosts) {
|
||||
export async function getAllCategories ({ allPosts, categoryOptions, sliceCount = 0 }) {
|
||||
if (!allPosts || !categoryOptions) {
|
||||
return []
|
||||
}
|
||||
|
||||
// 计数
|
||||
let categories = allPosts.map(p => p.category)
|
||||
categories = [...categories.flat()]
|
||||
const categoryObj = {}
|
||||
@@ -18,5 +18,19 @@ export async function getAllCategories (allPosts) {
|
||||
categoryObj[category] = 1
|
||||
}
|
||||
})
|
||||
return categoryObj
|
||||
const list = []
|
||||
categoryOptions.forEach(c => {
|
||||
const count = categoryObj[c.value]
|
||||
if (count) {
|
||||
list.push({ id: c.id, name: c.value, color: c.color, count })
|
||||
}
|
||||
})
|
||||
|
||||
// 按照数量排序
|
||||
// list.sort((a, b) => b.count - a.count)
|
||||
if (sliceCount && sliceCount > 0) {
|
||||
return list.slice(0, sliceCount)
|
||||
} else {
|
||||
return list
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user