完善编译,数据库支持多视图排序

This commit is contained in:
tangly1024
2023-07-30 15:22:09 +08:00
parent b4d1a1acc9
commit 49831089d9
16 changed files with 26 additions and 24 deletions

View File

@@ -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 []
}

View File

@@ -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
}

View File

@@ -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 []

View File

@@ -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'
})