Skip to content

Commit

Permalink
feat(支持复杂格式的config表格式配置):
Browse files Browse the repository at this point in the history
  • Loading branch information
qixing-jk committed Dec 17, 2024
1 parent dc728fa commit 13dfb9a
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions lib/notion/getNotionConfig.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/**
Expand All @@ -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;
}
}

0 comments on commit 13dfb9a

Please # to comment.