From 057f4d8881074d4e505b1179cbb7afde264206f0 Mon Sep 17 00:00:00 2001 From: anime Date: Wed, 18 Dec 2024 02:00:59 +0800 Subject: [PATCH] =?UTF-8?q?feat(=E6=94=AF=E6=8C=81=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E7=9A=84config=E8=A1=A8=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E9=85=8D=E7=BD=AE):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 13dfb9a9078fedaac94da15ae3ee44a32ea6cdf0) --- lib/notion/getNotionConfig.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index 9a8c5072..637c73ea 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -157,19 +157,12 @@ export async function getConfigMapFromConfigPage(allPages) { // 只导入生效的配置 if (config.enable) { // console.log('[Notion配置]', config.key, config.value) - notionConfig[config.key] = config.value || null + notionConfig[config.key] = parseTextToJson(config.value) || config.value || null // 配置不能是undefined,至少是null } } } - - // 最后检查Notion_Config页面的INLINE_CONFIG,是否是一个js对象 - const combine = Object.assign( - {}, - deepClone(notionConfig), - parseConfig(notionConfig?.INLINE_CONFIG) - ) - return combine + return notionConfig } /** @@ -191,3 +184,16 @@ export function parseConfig(configString) { return {} } } + +/** + * 解析文本为JSON + * @param text + * @returns {any|null} + */ +export function parseTextToJson(text) { + try { + return JSON.parse(text); + } catch (error) { + return null; + } +}