feat(支持复杂格式的config表格式配置):

(cherry picked from commit 13dfb9a9078fedaac94da15ae3ee44a32ea6cdf0)
This commit is contained in:
anime
2024-12-18 02:00:59 +08:00
parent 1c4cb7b0e4
commit 057f4d8881

View File

@@ -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;
}
}