多语言配置,starter主题微调、兼容

This commit is contained in:
tangly1024.com
2024-04-12 12:44:02 +08:00
parent 16779a0614
commit aefca7171e
10 changed files with 597 additions and 500 deletions

View File

@@ -7,6 +7,7 @@
*
*/
import { getDateValue, getTextContent } from 'notion-utils'
import { deepClone } from '../utils'
import getAllPageIds from './getAllPageIds'
import { getPostBlocks } from './getPostBlocks'
@@ -162,9 +163,12 @@ export async function getConfigMapFromConfigPage(allPages) {
}
// 最后检查Notion_Config页面的INLINE_CONFIG是否是一个js对象
const inlineConfigs = parseConfig(configPage?.INLINE_CONFIG)
return Object.assign({}, notionConfig, inlineConfigs)
const combine = Object.assign(
{},
deepClone(notionConfig),
parseConfig(notionConfig?.INLINE_CONFIG)
)
return combine
}
/**
@@ -176,19 +180,13 @@ export function parseConfig(configString) {
if (!configString) {
return {}
}
// 解析对象
try {
// 尝试解析为 JSON 对象
const jsonConfig = JSON.parse(configString)
return jsonConfig
} catch (error) {
// 如果解析失败,则尝试使用 eval()
try {
// eslint-disable-next-line no-eval
const config = eval('(' + configString + ')')
return config
} catch (evalError) {
console.error('解析 INLINE_CONFIG 配置时出错:', evalError)
return {}
}
// eslint-disable-next-line no-eval
const config = eval('(' + configString + ')')
return config
} catch (evalError) {
console.error('解析 eval(INLINE_CONFIG) 配置时出错:', evalError)
return {}
}
}