From e72a332cb7d0125ce5d6d601775385fd27f01757 Mon Sep 17 00:00:00 2001 From: ShH Y <74806550+1208nn@users.noreply.github.com> Date: Sat, 9 Dec 2023 14:53:08 +0800 Subject: [PATCH 1/4] optimize notionconfig --- lib/notion/getNotionConfig.js | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index 7d026fbd..23ccba64 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -24,7 +24,7 @@ export async function getConfigMapFromConfigPage(allPages) { return null } const configPage = allPages?.find(post => { - return post && post?.type && post?.type === 'CONFIG' + return post && post?.type && (post?.type === 'CONFIG' || post?.type === 'config' || post?.type === 'Config') }) if (!configPage) { @@ -33,10 +33,13 @@ export async function getConfigMapFromConfigPage(allPages) { } const configPageId = configPage.id - // console.log('[Notion配置]请求配置数据 ', configPage.id) - const pageRecordMap = await getPostBlocks(configPageId, 'config-table') - // console.log('配置中心Page', configPageId, pageRecordMap) - const content = pageRecordMap.block[configPageId].value.content + for (const table of ['config-table', 'Config-Table', 'CONFIG-TABLE']) { + // console.log('[Notion配置]请求配置数据 ', configPage.id) + var pageRecordMap = await getPostBlocks(configPageId, table) + // console.log('配置中心Page', configPageId, pageRecordMap) + var content = pageRecordMap.block[configPageId].value.content + if (content) break + } if (!content) { console.warn('[Notion配置] 未找到配置表格', pageRecordMap.block[configPageId], pageRecordMap.block[configPageId].value) @@ -119,9 +122,9 @@ export async function getConfigMapFromConfigPage(allPages) { if (properties) { // 将表格中的字段映射成 英文 const config = { - enable: properties['启用'] === 'Yes', - key: properties['配置名'], - value: properties['配置值'] + enable: properties['启用'] || properties['Enable'] === 'Yes', + key: properties['配置名'] || properties['Name'], + value: properties['配置值'] || properties['Value'] } // 只导入生效的配置 From 9db27468e8307411a55178885d6162ce752485ff Mon Sep 17 00:00:00 2001 From: ShH Y <74806550+1208nn@users.noreply.github.com> Date: Sat, 9 Dec 2023 15:07:34 +0800 Subject: [PATCH 2/4] fix --- lib/notion/getNotionConfig.js | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index 23ccba64..62e78914 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -32,13 +32,14 @@ export async function getConfigMapFromConfigPage(allPages) { return null } const configPageId = configPage.id - - for (const table of ['config-table', 'Config-Table', 'CONFIG-TABLE']) { - // console.log('[Notion配置]请求配置数据 ', configPage.id) - var pageRecordMap = await getPostBlocks(configPageId, table) - // console.log('配置中心Page', configPageId, pageRecordMap) - var content = pageRecordMap.block[configPageId].value.content + // console.log('[Notion配置]请求配置数据 ', configPage.id) + var pageRecordMap = await getPostBlocks(configPageId, 'config-table') + // console.log('配置中心Page', configPageId, pageRecordMap) + var content = pageRecordMap.block[configPageId].value.content + for (const table of ['Config-Table', 'CONFIG-TABLE']) { if (content) break + pageRecordMap = await getPostBlocks(configPageId, table) + content = pageRecordMap.block[configPageId].value.content } if (!content) { @@ -122,9 +123,9 @@ export async function getConfigMapFromConfigPage(allPages) { if (properties) { // 将表格中的字段映射成 英文 const config = { - enable: properties['启用'] || properties['Enable'] === 'Yes', - key: properties['配置名'] || properties['Name'], - value: properties['配置值'] || properties['Value'] + enable: properties['启用'] || properties.Enable === 'Yes', + key: properties['配置名'] || properties.Name, + value: properties['配置值'] || properties.Value } // 只导入生效的配置 From fccf47fa465e07a912fd974161cdb2ef8f928193 Mon Sep 17 00:00:00 2001 From: ShH Y <74806550+1208nn@users.noreply.github.com> Date: Sat, 9 Dec 2023 15:11:16 +0800 Subject: [PATCH 3/4] solve warnings --- lib/notion/getNotionConfig.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index 62e78914..3da592c9 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -33,9 +33,9 @@ export async function getConfigMapFromConfigPage(allPages) { } const configPageId = configPage.id // console.log('[Notion配置]请求配置数据 ', configPage.id) - var pageRecordMap = await getPostBlocks(configPageId, 'config-table') + let pageRecordMap = await getPostBlocks(configPageId, 'config-table') // console.log('配置中心Page', configPageId, pageRecordMap) - var content = pageRecordMap.block[configPageId].value.content + let content = pageRecordMap.block[configPageId].value.content for (const table of ['Config-Table', 'CONFIG-TABLE']) { if (content) break pageRecordMap = await getPostBlocks(configPageId, table) From 9492addd1d8abdb72aba057d5e9003b142a16ae2 Mon Sep 17 00:00:00 2001 From: ShH Y <74806550+1208nn@users.noreply.github.com> Date: Sat, 16 Dec 2023 09:18:48 +0800 Subject: [PATCH 4/4] Update getNotionConfig.js --- lib/notion/getNotionConfig.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index 3da592c9..984b6eb7 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -123,7 +123,7 @@ export async function getConfigMapFromConfigPage(allPages) { if (properties) { // 将表格中的字段映射成 英文 const config = { - enable: properties['启用'] || properties.Enable === 'Yes', + enable: (properties['启用'] || properties.Enable) === 'Yes', key: properties['配置名'] || properties.Name, value: properties['配置值'] || properties.Value }