修复映射Notion数据库字段

This commit is contained in:
tangly
2022-10-17 22:07:51 +08:00
parent 07d48ae632
commit 96d1a85a93
4 changed files with 28 additions and 18 deletions

View File

@@ -1,7 +1,7 @@
import MemoryCache from './memory_cache'
import FileCache from './local_file_cache'
import MongoCache from './mongo_db_cache'
const enableCache = true
import BLOG from '@/blog.config'
let api
if (process.env.MONGO_DB_URL && process.env.MONGO_DB_NAME) {
@@ -18,7 +18,7 @@ if (process.env.MONGO_DB_URL && process.env.MONGO_DB_NAME) {
* @returns
*/
export async function getDataFromCache(key) {
if (!enableCache) {
if (!BLOG.ENABLE_CACHE) {
return null
}
const dataFromCache = await api.getCache(key)
@@ -29,14 +29,14 @@ export async function getDataFromCache(key) {
}
export async function setDataToCache(key, data) {
if (!enableCache || !data) {
if (!BLOG.ENABLE_CACHE || !data) {
return
}
await api.setCache(key, data)
}
export async function delCacheData(key) {
if (!enableCache) {
if (!BLOG.ENABLE_CACHE) {
return
}
await api.delCache(key)

View File

@@ -11,7 +11,7 @@ export default function getAllPageIds (collectionQuery, collectionId, collection
view?.collection_group_results?.blockIds?.forEach(id => pageSet.add(id)) // table视图
})
pageIds = [...pageSet]
console.log('PageIds: 从collectionQuery获取', collectionQuery)
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)

View File

@@ -251,13 +251,21 @@ async function getPageRecordMapByNotionAPI({ pageId, from }) {
collectionData.push(properties)
}
}
// 读取映射 配置
console.log('当前Notion映射配置-(在blog.config.js中配置)', BLOG.NOTION_PROPERTY_NAME)
const { type, status } = BLOG.NOTION_PROPERTY_NAME
const allPages = collectionData.filter(post => {
return post.title && ['Page'].indexOf(post?.type?.[0]) > -1 && (post?.status?.[0] === 'Published' || post?.status?.[0] === 'Invisible')
return post && post[type] &&
['Page'].indexOf(post[type]?.[0]) > -1 &&
(post[status]?.[0] === 'Published' || post[status]?.[0] === 'Invisible')
})
const allPosts = collectionData.filter(post => {
return post.title && ['Post'].indexOf(post?.type?.[0]) > -1 && post?.status?.[0] === 'Published'
return post && post[status] &&
['Post'].indexOf(post[type]?.[0]) > -1 &&
post[status]?.[0] === 'Published'
})
console.error('全部单页', allPages.length, '全部博客', allPosts.length)
// Sort by date
if (BLOG.POSTS_SORT_BY === 'date') {