NEXT主题,分类标签调整

This commit is contained in:
tangly1024
2022-03-01 12:49:38 +08:00
parent 0b2046b658
commit b89177644f
10 changed files with 69 additions and 46 deletions

View File

@@ -11,6 +11,7 @@ import { getAllTags } from './getAllTags'
* @param {*} pageId
* @param {*} from
* @param latestPostCount 截取最新文章数量
* @param categoryCount
* @param tagsCount 截取标签数量
* @param pageType 过滤的文章类型,数组格式 ['Page','Post']
* @returns {
@@ -27,15 +28,17 @@ export async function getGlobalNotionData ({
pageId = BLOG.NOTION_PAGE_ID,
from,
latestPostCount = 5,
tagsCount = 16,
categoryCount = BLOG.PREVIEW_CATEGORY_COUNT,
tagsCount = BLOG.PREVIEW_TAG_COUNT,
pageType = ['Post']
}) {
const notionPageData = await getNotionPageData({ pageId, from })
const tagOptions = notionPageData.tagOptions
const categoryOptions = notionPageData.categoryOptions
const allPosts = await getAllPosts({ notionPageData, from, pageType })
const postCount = await getAllPostCount({ notionPageData, from })
const customNav = await getCustomNav({ notionPageData })
const categories = await getAllCategories(allPosts)
const categories = await getAllCategories({ allPosts, categoryOptions, sliceCount: categoryCount })
const tags = await getAllTags({ allPosts, tagOptions, sliceCount: tagsCount })
const latestPosts = await getLatestPosts({ notionPageData, from, latestPostCount })
return { allPosts, latestPosts, categories, postCount, customNav, tags }
@@ -110,6 +113,11 @@ function getTagOptions (schema) {
return tagSchema?.options || {}
}
function getCategoryOptions (schema) {
const categorySchema = Object.values(schema).find(e => e.name === 'category')
return categorySchema?.options || {}
}
/**
* 调用NotionAPI获取Page数据
* @returns {Promise<JSX.Element|null|*>}
@@ -119,7 +127,6 @@ async function getPageRecordMapByNotionAPI ({ pageId, from }) {
if (!pageRecordMap) {
return []
}
pageId = idToUuid(pageId)
const collection = Object.values(pageRecordMap.collection)[0]?.value
const collectionQuery = pageRecordMap.collection_query
@@ -127,6 +134,7 @@ async function getPageRecordMapByNotionAPI ({ pageId, from }) {
const schema = collection?.schema
const rawMetadata = block[pageId].value
const tagOptions = getTagOptions(schema)
const categoryOptions = getCategoryOptions(schema)
// Check Type Page-Database和Inline-Database
if (
@@ -143,6 +151,7 @@ async function getPageRecordMapByNotionAPI ({ pageId, from }) {
block,
schema,
tagOptions,
categoryOptions,
rawMetadata
}
}