mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-17 23:16:50 +00:00
完善编译,数据库支持多视图排序
This commit is contained in:
@@ -14,7 +14,7 @@ import { isIterable } from '../utils'
|
||||
* @returns {Promise<{}|*[]>}
|
||||
*/
|
||||
export function getAllCategories({ allPages, categoryOptions, sliceCount = 0 }) {
|
||||
const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
if (!allPosts || !categoryOptions) {
|
||||
return []
|
||||
}
|
||||
|
||||
@@ -4,7 +4,15 @@ export default function getAllPageIds (collectionQuery, collectionId, collection
|
||||
return []
|
||||
}
|
||||
let pageIds = []
|
||||
if (collectionQuery && Object.values(collectionQuery).length > 0) {
|
||||
// 优先按照第一个视图排序
|
||||
if (viewIds && viewIds.length > 0) {
|
||||
const ids = collectionView[viewIds[0]].value.page_sort
|
||||
// console.log('PageIds: 从viewId获取', viewIds)
|
||||
for (const id of ids) {
|
||||
pageIds.push(id)
|
||||
}
|
||||
// 否则按照数据库原始排序
|
||||
} else if (collectionQuery && Object.values(collectionQuery).length > 0) {
|
||||
const pageSet = new Set()
|
||||
Object.values(collectionQuery[collectionId]).forEach(view => {
|
||||
view?.blockIds?.forEach(id => pageSet.add(id)) // group视图
|
||||
@@ -12,12 +20,6 @@ export default function getAllPageIds (collectionQuery, collectionId, collection
|
||||
})
|
||||
pageIds = [...pageSet]
|
||||
// console.log('PageIds: 从collectionQuery获取', collectionQuery, pageIds.length)
|
||||
} else if (viewIds && viewIds.length > 0) {
|
||||
const ids = collectionView[viewIds[0]].value.page_sort
|
||||
// console.log('PageIds: 从viewId获取', viewIds)
|
||||
for (const id of ids) {
|
||||
pageIds.push(id)
|
||||
}
|
||||
}
|
||||
return pageIds
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import { isIterable } from '../utils'
|
||||
* @returns {Promise<{}|*[]>}
|
||||
*/
|
||||
export function getAllTags({ allPages, sliceCount = 0, tagOptions }) {
|
||||
const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
|
||||
if (!allPosts || !tagOptions) {
|
||||
return []
|
||||
|
||||
@@ -180,7 +180,7 @@ function getSiteInfo({ collection, block }) {
|
||||
* @param {*} param0
|
||||
*/
|
||||
export function getNavPages({ allPages }) {
|
||||
const allNavPages = allPages.filter(post => {
|
||||
const allNavPages = allPages?.filter(post => {
|
||||
return post && post?.slug && (!post?.slug?.startsWith('http')) && post?.type === 'Post' && post?.status === 'Published'
|
||||
})
|
||||
|
||||
|
||||
@@ -70,7 +70,7 @@ export async function getStaticProps({ params: { prefix, slug } }) {
|
||||
}
|
||||
|
||||
// 推荐关联文章处理
|
||||
const allPosts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
const allPosts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
if (allPosts && allPosts.length > 0) {
|
||||
const index = allPosts.indexOf(props.post)
|
||||
props.prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0]
|
||||
|
||||
@@ -135,7 +135,7 @@ export async function getStaticProps({ params: { prefix } }) {
|
||||
}
|
||||
|
||||
// 推荐关联文章处理
|
||||
const allPosts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
const allPosts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
if (allPosts && allPosts.length > 0) {
|
||||
const index = allPosts.indexOf(props.post)
|
||||
props.prev = allPosts.slice(index - 1, index)[0] ?? allPosts.slice(-1)[0]
|
||||
|
||||
@@ -44,7 +44,7 @@ const ArchiveIndex = props => {
|
||||
export async function getStaticProps() {
|
||||
const props = await getGlobalData({ from: 'archive-index' })
|
||||
// 处理分页
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
delete props.allPages
|
||||
|
||||
const postsSortByDate = Object.create(props.posts)
|
||||
|
||||
@@ -37,7 +37,7 @@ export async function getStaticProps({ params: { category } }) {
|
||||
let props = await getGlobalData({ from })
|
||||
|
||||
// 过滤状态
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
// 处理过滤
|
||||
props.posts = props.posts.filter(post => post && post.category && post.category.includes(category))
|
||||
// 处理文章页数
|
||||
|
||||
@@ -37,7 +37,7 @@ export async function getStaticProps({ params: { category, page } }) {
|
||||
let props = await getGlobalData({ from })
|
||||
|
||||
// 过滤状态类型
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category))
|
||||
props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category))
|
||||
// 处理文章页数
|
||||
props.postCount = props.posts.length
|
||||
// 处理分页
|
||||
@@ -61,7 +61,7 @@ export async function getStaticPaths() {
|
||||
|
||||
categoryOptions?.forEach(category => {
|
||||
// 过滤状态类型
|
||||
const categoryPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category.name))
|
||||
const categoryPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post.category && post.category.includes(category.name))
|
||||
// 处理文章页数
|
||||
const postCount = categoryPosts.length
|
||||
const totalPages = Math.ceil(postCount / BLOG.POSTS_PER_PAGE)
|
||||
|
||||
@@ -26,7 +26,7 @@ export async function getStaticProps() {
|
||||
const props = await getGlobalData({ from })
|
||||
|
||||
const { siteInfo } = props
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
|
||||
const meta = {
|
||||
title: `${siteInfo?.title} | ${siteInfo?.description}`,
|
||||
|
||||
@@ -45,7 +45,7 @@ export async function getStaticProps({ params: { page } }) {
|
||||
const from = `page-${page}`
|
||||
const props = await getGlobalData({ from })
|
||||
const { allPages } = props
|
||||
const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
// 处理分页
|
||||
props.posts = allPosts.slice(BLOG.POSTS_PER_PAGE * (page - 1), BLOG.POSTS_PER_PAGE * page)
|
||||
props.page = page
|
||||
|
||||
@@ -36,7 +36,7 @@ export async function getStaticProps({ params: { keyword } }) {
|
||||
pageType: ['Post']
|
||||
})
|
||||
const { allPages } = props
|
||||
const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
props.posts = await filterByMemCache(allPosts, keyword)
|
||||
props.postCount = props.posts.length
|
||||
// 处理分页
|
||||
|
||||
@@ -36,7 +36,7 @@ export async function getStaticProps({ params: { keyword, page } }) {
|
||||
pageType: ['Post']
|
||||
})
|
||||
const { allPages } = props
|
||||
const allPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
const allPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
props.posts = await filterByMemCache(allPosts, keyword)
|
||||
props.postCount = props.posts.length
|
||||
// 处理分页
|
||||
|
||||
@@ -55,7 +55,7 @@ export async function getStaticProps() {
|
||||
pageType: ['Post']
|
||||
})
|
||||
const { allPages } = props
|
||||
props.posts = allPages.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
props.posts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published')
|
||||
return {
|
||||
props,
|
||||
revalidate: parseInt(BLOG.NEXT_REVALIDATE_SECOND)
|
||||
|
||||
@@ -33,7 +33,7 @@ export async function getStaticProps({ params: { tag } }) {
|
||||
const props = await getGlobalData({ from })
|
||||
|
||||
// 过滤状态
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag))
|
||||
props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag))
|
||||
|
||||
// 处理文章页数
|
||||
props.postCount = props.posts.length
|
||||
|
||||
@@ -27,7 +27,7 @@ export async function getStaticProps({ params: { tag, page } }) {
|
||||
const from = 'tag-page-props'
|
||||
const props = await getGlobalData({ from })
|
||||
// 过滤状态、标签
|
||||
props.posts = props.allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag))
|
||||
props.posts = props.allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag))
|
||||
// 处理文章数
|
||||
props.postCount = props.posts.length
|
||||
// 处理分页
|
||||
@@ -48,7 +48,7 @@ export async function getStaticPaths() {
|
||||
const paths = []
|
||||
tagOptions?.forEach(tag => {
|
||||
// 过滤状态类型
|
||||
const tagPosts = allPages.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag.name))
|
||||
const tagPosts = allPages?.filter(page => page.type === 'Post' && page.status === 'Published').filter(post => post && post?.tags && post?.tags.includes(tag.name))
|
||||
// 处理文章页数
|
||||
const postCount = tagPosts.length
|
||||
const totalPages = Math.ceil(postCount / BLOG.POSTS_PER_PAGE)
|
||||
|
||||
Reference in New Issue
Block a user