From 04ffbbb7ef33efc84028ee245d0cdabfd6fe3afe Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Tue, 17 Jun 2025 10:55:56 +0800 Subject: [PATCH] =?UTF-8?q?Notion=E6=95=B0=E6=8D=AE=E5=BA=93=E6=94=AF?= =?UTF-8?q?=E6=8C=81=E9=85=8D=E7=BD=AE=E8=A7=86=E5=9B=BE=E7=B4=A2=E5=BC=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- conf/notion.config.js | 5 +++++ lib/notion/getAllPageIds.js | 5 +++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/conf/notion.config.js b/conf/notion.config.js index f402c8b3..dc98f573 100644 --- a/conf/notion.config.js +++ b/conf/notion.config.js @@ -1,8 +1,13 @@ /** * 读取Notion相关的配置 * 如果需要在Notion中添加自定义字段,可以修改此文件 + * 此文件内容可以通过环境变量覆盖,但是不支持用NOTION_CONFIG覆盖 */ module.exports = { + // Notion数据库索引,取notion的第几个视图作为站点数据和排序依据 + NOTION_INDEX: process.env.NEXT_PUBLIC_NOTION_INDEX || 0, // 默认取Notion数据库中的第1个视图 + // 由于计算机是从0开始计数、而非从1开始。因此如果要取第二个视图,可以传1,取第三个视图传2,以此类推,取数据库的最后一个视图可以传-1。 + // 自定义配置notion数据库字段名 NOTION_PROPERTY_NAME: { password: process.env.NEXT_PUBLIC_NOTION_PROPERTY_PASSWORD || 'password', diff --git a/lib/notion/getAllPageIds.js b/lib/notion/getAllPageIds.js index 8b85f9e5..acda6b95 100644 --- a/lib/notion/getAllPageIds.js +++ b/lib/notion/getAllPageIds.js @@ -1,13 +1,14 @@ +import BLOG from "@/blog.config" export default function getAllPageIds (collectionQuery, collectionId, collectionView, viewIds) { if (!collectionQuery && !collectionView) { return [] } - // 优先按照第一个视图排序 let pageIds = [] try { + // Notion数据库中的第几个视图用于站点展示和排序: + const groupIndex = BLOG.NOTION_INDEX || 0 if (viewIds && viewIds.length > 0) { - const groupIndex = viewIds.length > 0 ? viewIds.length - 1 : 0 const ids = collectionQuery[collectionId][viewIds[groupIndex]]?.collection_group_results?.blockIds || [] for (const id of ids) { pageIds.push(id)