保留inline_config

This commit is contained in:
tangly1024
2024-12-28 16:40:48 +08:00
parent 02790ab8a3
commit f52fcaf1c0

View File

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