mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-14 23:16:49 +00:00
23 lines
469 B
JavaScript
23 lines
469 B
JavaScript
/**
|
|
* 获取所有文章的分类
|
|
* @param allPosts
|
|
* @returns {Promise<{}|*[]>}
|
|
*/
|
|
export async function getAllCategories (allPosts) {
|
|
if (!allPosts) {
|
|
return []
|
|
}
|
|
|
|
let categories = allPosts.map(p => p.category)
|
|
categories = [...categories.flat()]
|
|
const categoryObj = {}
|
|
categories.forEach(category => {
|
|
if (category in categoryObj) {
|
|
categoryObj[category]++
|
|
} else {
|
|
categoryObj[category] = 1
|
|
}
|
|
})
|
|
return categoryObj
|
|
}
|