From f52fcaf1c0285564a6365e00fe1d14cd9637a179 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sat, 28 Dec 2024 16:40:48 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=9D=E7=95=99inline=5Fconfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionConfig.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index b8ba4cd1..029c7b96 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -157,19 +157,24 @@ export async function getConfigMapFromConfigPage(allPages) { // 只导入生效的配置 if (config.enable) { // console.log('[Notion配置]', config.key, config.value) - notionConfig[config.key] = parseTextToJson(config.value) || config.value || null + notionConfig[config.key] = + parseTextToJson(config.value) || config.value || null // 配置不能是undefined,至少是null } } } - - // 将INLINE_CONFIG合并,@see https://docs.tangly1024.com/article/notion-next-inline-config - const combine = Object.assign( - {}, - deepClone(notionConfig), - parseConfig(notionConfig?.INLINE_CONFIG) - ) + let combine = notionConfig + try { + // 将INLINE_CONFIG合并,@see https://docs.tangly1024.com/article/notion-next-inline-config + combine = Object.assign( + {}, + deepClone(notionConfig), + notionConfig?.INLINE_CONFIG + ) + } catch (err) { + console.warn('解析 INLINE_CONFIG 配置时出错,请检查JSON格式', err) + } return combine } @@ -188,7 +193,10 @@ export function parseConfig(configString) { const config = eval('(' + configString + ')') return config } catch (evalError) { - console.error('解析 eval(INLINE_CONFIG) 配置时出错:', evalError) + console.warn( + '解析 eval(INLINE_CONFIG) 配置时出错,请检查JSON格式', + evalError + ) return {} } } @@ -200,8 +208,8 @@ export function parseConfig(configString) { */ export function parseTextToJson(text) { try { - return JSON.parse(text); + return JSON.parse(text) } catch (error) { - return null; + return null } }