mirror of
https://github.com/d0zingcat/NotionNext.git
synced 2026-05-21 15:09:43 +00:00
Merge pull request #3077 from qixing-jk/feat-notion-config
Notion config的配置项可以使用对象数组等复杂结构和HEO主题的站点信息文案支持从Notion配置
This commit is contained in:
@@ -157,18 +157,24 @@ export async function getConfigMapFromConfigPage(allPages) {
|
|||||||
// 只导入生效的配置
|
// 只导入生效的配置
|
||||||
if (config.enable) {
|
if (config.enable) {
|
||||||
// console.log('[Notion配置]', config.key, config.value)
|
// console.log('[Notion配置]', config.key, config.value)
|
||||||
notionConfig[config.key] = config.value || null
|
notionConfig[config.key] =
|
||||||
|
parseTextToJson(config.value) || config.value || null
|
||||||
// 配置不能是undefined,至少是null
|
// 配置不能是undefined,至少是null
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// 最后检查Notion_Config页面的INLINE_CONFIG,是否是一个js对象
|
let combine = notionConfig
|
||||||
const combine = Object.assign(
|
try {
|
||||||
{},
|
// 将INLINE_CONFIG合并,@see https://docs.tangly1024.com/article/notion-next-inline-config
|
||||||
deepClone(notionConfig),
|
combine = Object.assign(
|
||||||
parseConfig(notionConfig?.INLINE_CONFIG)
|
{},
|
||||||
)
|
deepClone(notionConfig),
|
||||||
|
notionConfig?.INLINE_CONFIG
|
||||||
|
)
|
||||||
|
} catch (err) {
|
||||||
|
console.warn('解析 INLINE_CONFIG 配置时出错,请检查JSON格式', err)
|
||||||
|
}
|
||||||
return combine
|
return combine
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -187,7 +193,23 @@ export function parseConfig(configString) {
|
|||||||
const config = eval('(' + configString + ')')
|
const config = eval('(' + configString + ')')
|
||||||
return config
|
return config
|
||||||
} catch (evalError) {
|
} catch (evalError) {
|
||||||
console.error('解析 eval(INLINE_CONFIG) 配置时出错:', evalError)
|
console.warn(
|
||||||
|
'解析 eval(INLINE_CONFIG) 配置时出错,请检查JSON格式',
|
||||||
|
evalError
|
||||||
|
)
|
||||||
return {}
|
return {}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 解析文本为JSON
|
||||||
|
* @param text
|
||||||
|
* @returns {any|null}
|
||||||
|
*/
|
||||||
|
export function parseTextToJson(text) {
|
||||||
|
try {
|
||||||
|
return JSON.parse(text)
|
||||||
|
} catch (error) {
|
||||||
|
return null
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -11,31 +11,35 @@ export function AnalyticsCard(props) {
|
|||||||
const today = new Date()
|
const today = new Date()
|
||||||
const diffTime = today.getTime() - targetDate.getTime() // 获取两个日期之间的毫秒数差值
|
const diffTime = today.getTime() - targetDate.getTime() // 获取两个日期之间的毫秒数差值
|
||||||
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) // 将毫秒数差值转换为天数差值
|
const diffDays = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) // 将毫秒数差值转换为天数差值
|
||||||
|
const postCountTitle = siteConfig('HEO_POST_COUNT_TITLE', null, CONFIG)
|
||||||
|
const siteTimeTitle = siteConfig('HEO_SITE_TIME_TITLE', null, CONFIG)
|
||||||
|
const siteVisitTitle = siteConfig('HEO_SITE_VISIT_TITLE', null, CONFIG)
|
||||||
|
const siteVisitorTitle = siteConfig('HEO_SITE_VISITOR_TITLE', null, CONFIG)
|
||||||
|
|
||||||
const { postCount } = props
|
const { postCount } = props
|
||||||
return <>
|
return <>
|
||||||
<div className='text-md flex flex-col space-y-1 justify-center px-3'>
|
<div className='text-md flex flex-col space-y-1 justify-center px-3'>
|
||||||
<div className='inline'>
|
<div className='inline'>
|
||||||
<div className='flex justify-between'>
|
<div className='flex justify-between'>
|
||||||
<div>文章数:</div>
|
<div>{postCountTitle}</div>
|
||||||
<div>{postCount}</div>
|
<div>{postCount}</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='inline'>
|
<div className='inline'>
|
||||||
<div className='flex justify-between'>
|
<div className='flex justify-between'>
|
||||||
<div>建站天数:</div>
|
<div>{siteTimeTitle}</div>
|
||||||
<div>{diffDays} 天</div>
|
<div>{diffDays} 天</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='hidden busuanzi_container_page_pv'>
|
<div className='hidden busuanzi_container_page_pv'>
|
||||||
<div className='flex justify-between'>
|
<div className='flex justify-between'>
|
||||||
<div>访问量:</div>
|
<div>{siteVisitTitle}</div>
|
||||||
<div className='busuanzi_value_page_pv' />
|
<div className='busuanzi_value_page_pv' />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div className='hidden busuanzi_container_site_uv'>
|
<div className='hidden busuanzi_container_site_uv'>
|
||||||
<div className='flex justify-between'>
|
<div className='flex justify-between'>
|
||||||
<div>访客数:</div>
|
<div>{siteVisitorTitle}</div>
|
||||||
<div className='busuanzi_value_site_uv' />
|
<div className='busuanzi_value_site_uv' />
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@@ -122,6 +122,12 @@ const CONFIG = {
|
|||||||
HEO_SOCIAL_CARD_TITLE_3: '点击加入社群',
|
HEO_SOCIAL_CARD_TITLE_3: '点击加入社群',
|
||||||
HEO_SOCIAL_CARD_URL: 'https://docs.tangly1024.com/article/how-to-question',
|
HEO_SOCIAL_CARD_URL: 'https://docs.tangly1024.com/article/how-to-question',
|
||||||
|
|
||||||
|
// 底部统计面板文案
|
||||||
|
HEO_POST_COUNT_TITLE: '文章数:',
|
||||||
|
HEO_SITE_TIME_TITLE: '建站天数:',
|
||||||
|
HEO_SITE_VISIT_TITLE: '访问量:',
|
||||||
|
HEO_SITE_VISITOR_TITLE: '访客数:',
|
||||||
|
|
||||||
// ***** 以下配置无效,只是预留开发 ****
|
// ***** 以下配置无效,只是预留开发 ****
|
||||||
// 菜单配置
|
// 菜单配置
|
||||||
HEO_MENU_INDEX: true, // 显示首页
|
HEO_MENU_INDEX: true, // 显示首页
|
||||||
|
|||||||
Reference in New Issue
Block a user