mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-16 15:09:28 +00:00
Merge branch 'main' into fix-article-cover
# Conflicts: # lib/notion/getAllPosts.js # lib/notion/getNotionData.js
This commit is contained in:
@@ -1,3 +1,2 @@
|
||||
export { getAllPosts } from './notion/getAllPosts'
|
||||
export { getAllTags } from './notion/getAllTags'
|
||||
export { getPostBlocks } from './notion/getPostBlocks'
|
||||
|
||||
@@ -5,7 +5,6 @@ import { idToUuid } from 'notion-utils'
|
||||
import { defaultMapImageUrl } from 'react-notion-x'
|
||||
import { deepClone, isIterable } from '../utils'
|
||||
import getAllPageIds from './getAllPageIds'
|
||||
import { getAllPosts } from './getAllPosts'
|
||||
import { getAllTags } from './getAllTags'
|
||||
import getPageProperties from './getPageProperties'
|
||||
|
||||
@@ -81,14 +80,16 @@ export async function getNotionPageData({ pageId, from }) {
|
||||
* @param notionPageData
|
||||
* @returns {Promise<[]|*[]>}
|
||||
*/
|
||||
function getCustomNav({ allPage }) {
|
||||
function getCustomNav({ allPages }) {
|
||||
const customNav = []
|
||||
if (allPage && allPage.length > 0) {
|
||||
allPage.forEach(p => {
|
||||
if (p?.slug?.indexOf('http') === 0) {
|
||||
customNav.push({ icon: p.icon || null, name: p.title, to: p.slug, show: true })
|
||||
} else {
|
||||
customNav.push({ icon: p.icon || null, name: p.title, to: '/' + p.slug, show: true })
|
||||
if (allPages && allPages.length > 0) {
|
||||
allPages.forEach(p => {
|
||||
if (p?.status?.[0] === 'Published') {
|
||||
if (p?.slug?.indexOf('http') === 0) {
|
||||
customNav.push({ icon: p.icon || null, name: p.title, to: p.slug, show: true })
|
||||
} else {
|
||||
customNav.push({ icon: p.icon || null, name: p.title, to: '/' + p.slug, show: true })
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
@@ -235,11 +236,11 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
|
||||
const tagOptions = getTagOptions(schema)
|
||||
const categoryOptions = getCategoryOptions(schema)
|
||||
const viewIds = rawMetadata?.view_ids
|
||||
const data = []
|
||||
const collectionData = []
|
||||
const pageIds = getAllPageIds(collectionQuery, collectionId, collectionView, viewIds)
|
||||
const siteInfo = getBlogInfo({ collection, block })
|
||||
if (pageIds?.length === 0) {
|
||||
console.error('获取到的文章列表为空,请检查notion模板', collectionQuery, collection, pageRecordMap)
|
||||
console.error('获取到的文章列表为空,请检查notion模板', collectionQuery, collection, collectionView, viewIds, pageRecordMap)
|
||||
}
|
||||
for (let i = 0; i < pageIds.length; i++) {
|
||||
const id = pageIds[i]
|
||||
@@ -247,20 +248,30 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
|
||||
if (!value) {
|
||||
continue
|
||||
}
|
||||
collectionData.push(properties)
|
||||
const properties = (await getPageProperties(id, block, schema, null, tagOptions, siteInfo)) || null
|
||||
if (properties) {
|
||||
data.push(properties)
|
||||
}
|
||||
}
|
||||
|
||||
const allPage = data.filter(post => {
|
||||
return post.title && post?.status?.[0] === 'Published' && ['Page'].indexOf(post?.type?.[0]) > -1
|
||||
const allPages = collectionData.filter(post => {
|
||||
return post.title && ['Page'].indexOf(post?.type?.[0]) > -1 && (post?.status?.[0] === 'Published' || post?.status?.[0] === 'Invisible')
|
||||
})
|
||||
const allPosts = data.filter(post => {
|
||||
return post.title && post?.status?.[0] === 'Published' && ['Post'].indexOf(post?.type?.[0]) > -1
|
||||
const allPosts = collectionData.filter(post => {
|
||||
return post.title && ['Post'].indexOf(post?.type?.[0]) > -1 && post?.status?.[0] === 'Published'
|
||||
})
|
||||
|
||||
const customNav = getCustomNav({ allPage })
|
||||
// Sort by date
|
||||
if (BLOG.POSTS_SORT_BY === 'date') {
|
||||
allPosts.sort((a, b) => {
|
||||
const dateA = new Date(a?.date?.start_date || a.createdTime)
|
||||
const dateB = new Date(b?.date?.start_date || b.createdTime)
|
||||
return dateB - dateA
|
||||
})
|
||||
}
|
||||
|
||||
const customNav = getCustomNav({ allPages })
|
||||
const postCount = allPosts?.length || 0
|
||||
const categories = getAllCategories({ allPosts, categoryOptions, sliceCount: BLOG.PREVIEW_CATEGORY_COUNT })
|
||||
const tags = getAllTags({ allPosts, tagOptions, sliceCount: BLOG.PREVIEW_TAG_COUNT })
|
||||
@@ -268,6 +279,8 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
|
||||
|
||||
return {
|
||||
siteInfo,
|
||||
allPages,
|
||||
allPosts,
|
||||
collection,
|
||||
collectionQuery,
|
||||
collectionId,
|
||||
|
||||
Reference in New Issue
Block a user