mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-18 07:26:48 +00:00
feature:
文章分类功能
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
export { getAllPosts } from './notion/getAllPosts'
|
||||
export { getAllTags } from './notion/getAllTags'
|
||||
export { getPostBlocks } from './notion/getPostBlocks'
|
||||
export { getAllCategories } from './notion/getAllCategories'
|
||||
|
||||
22
lib/notion/getAllCategories.js
Normal file
22
lib/notion/getAllCategories.js
Normal file
@@ -0,0 +1,22 @@
|
||||
/**
|
||||
* 获取所有文章的分类
|
||||
* @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
|
||||
}
|
||||
Reference in New Issue
Block a user