diff --git a/blog.config.js b/blog.config.js index bf271a5e..212b2801 100644 --- a/blog.config.js +++ b/blog.config.js @@ -128,20 +128,22 @@ const BLOG = { ADSENSE_GOOGLE_ID: process.env.NEXT_PUBLIC_ADSENSE_GOOGLE_ID || '', // 谷歌广告ID e.g ca-pub-xxxxxxxxxxxxxxxx - // 无关紧要的配置 // 自定义配置notion数据库字段名 NOTION_PROPERTY_NAME: { - password: 'password', - type: 'type', - title: 'title', - status: 'status', - summary: 'summary', - slug: 'slug', - category: 'category', - date: 'date', - tags: 'tags', - icon: 'icon' + password: process.env.NEXT_PUBLIC_NOTION_PROPERTY_PASSWORD || 'password', + type: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TYPE || 'type', + title: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TITLE || 'title', + status: process.env.NEXT_PUBLIC_NOTION_PROPERTY_STATUS || 'status', + summary: process.env.NEXT_PUBLIC_NOTION_PROPERTY_SUMMARY || 'summary', + slug: process.env.NEXT_PUBLIC_NOTION_PROPERTY_SLUG || 'slug', + category: process.env.NEXT_PUBLIC_NOTION_PROPERTY_CATEGORY || 'category', + date: process.env.NEXT_PUBLIC_NOTION_PROPERTY_DATE || 'date', + tags: process.env.NEXT_PUBLIC_NOTION_PROPERTY_TAGS || 'tags', + icon: process.env.NEXT_PUBLIC_NOTION_PROPERTY_ICON || 'icon' }, + + ENABLE_CACHE: false, // 开启缓存 会将Notion数据缓存在内存中,稍微提升访问速度,但要更新内容需要多次刷新页面 + AVATAR: '/avatar.png', // 作者头像,被notion中的ICON覆盖。如果没有ICON则取public目录下的avatar.png TITLE: process.env.NEXT_PUBLIC_TITLE || 'NotionNext BLOG', // 站点标题 ,被notion中的页面标题覆盖 DESCRIPTION: diff --git a/lib/cache/cache_manager.js b/lib/cache/cache_manager.js index 6554b014..2a4d8e36 100644 --- a/lib/cache/cache_manager.js +++ b/lib/cache/cache_manager.js @@ -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) diff --git a/lib/notion/getAllPageIds.js b/lib/notion/getAllPageIds.js index 1fbca908..44b80d38 100644 --- a/lib/notion/getAllPageIds.js +++ b/lib/notion/getAllPageIds.js @@ -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) diff --git a/lib/notion/getNotionData.js b/lib/notion/getNotionData.js index bf54561c..b243fadf 100644 --- a/lib/notion/getNotionData.js +++ b/lib/notion/getNotionData.js @@ -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') {