优化:POST_URL_PREFIX 和 PSEUDO_STATIC支持在NOTION_CONFIG中配置

This commit is contained in:
tangly1024.com
2024-05-10 18:23:27 +08:00
parent 021ea08f47
commit 0da9e605ec
3 changed files with 70 additions and 102 deletions

View File

@@ -4,11 +4,14 @@ import { getAllCategories } from '@/lib/notion/getAllCategories'
import getAllPageIds from '@/lib/notion/getAllPageIds'
import { getAllTags } from '@/lib/notion/getAllTags'
import { getConfigMapFromConfigPage } from '@/lib/notion/getNotionConfig'
import getPageProperties from '@/lib/notion/getPageProperties'
import getPageProperties, {
adjustPageProperties
} from '@/lib/notion/getPageProperties'
import { getPostBlocks, getSingleBlock } from '@/lib/notion/getPostBlocks'
import { compressImage, mapImgUrl } from '@/lib/notion/mapImage'
import { deepClone } from '@/lib/utils'
import { idToUuid } from 'notion-utils'
import { siteConfig } from '../config'
import { extractLangId, extractLangPrefix } from '../utils/pageId'
export { getAllTags } from '../notion/getAllTags'
@@ -442,14 +445,19 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
}
}
// 文章计数
let postCount = 0
// 站点配置优先读取配置表格否则读取blog.config.js 文件
const NOTION_CONFIG = (await getConfigMapFromConfigPage(collectionData)) || {}
// 处理每一条数据的字段
collectionData.forEach(function (element) {
adjustPageProperties(element, NOTION_CONFIG)
})
const siteInfo = getSiteInfo({ collection, block, pageId })
// 文章计数
let postCount = 0
// 查找所有的Post和Page
const allPages = collectionData.filter(post => {
if (post?.type === 'Post' && post.status === 'Published') {
@@ -464,7 +472,7 @@ async function getDataBaseInfoByNotionAPI({ pageId, from }) {
})
// Sort by date
if (BLOG.POSTS_SORT_BY === 'date') {
if (siteConfig('POSTS_SORT_BY', '', NOTION_CONFIG) === 'date') {
allPages.sort((a, b) => {
return b?.publishDate - a?.publishDate
})