From 057f4d8881074d4e505b1179cbb7afde264206f0 Mon Sep 17 00:00:00 2001 From: anime Date: Wed, 18 Dec 2024 02:00:59 +0800 Subject: [PATCH 1/4] =?UTF-8?q?feat(=E6=94=AF=E6=8C=81=E5=A4=8D=E6=9D=82?= =?UTF-8?q?=E6=A0=BC=E5=BC=8F=E7=9A=84config=E8=A1=A8=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E9=85=8D=E7=BD=AE):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 13dfb9a9078fedaac94da15ae3ee44a32ea6cdf0) --- lib/notion/getNotionConfig.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index 9a8c5072350..637c73eae84 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -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; + } +} From 96038640039d664696ece91f3ca3d89668b3b8ea Mon Sep 17 00:00:00 2001 From: anime Date: Thu, 19 Dec 2024 18:12:06 +0800 Subject: [PATCH 2/4] =?UTF-8?q?feat(HEO=E4=B8=BB=E9=A2=98=EF=BC=9A?= =?UTF-8?q?=E6=94=AF=E6=8C=81=E6=96=87=E6=A1=88=E4=BB=8Econfig=E8=8E=B7?= =?UTF-8?q?=E5=8F=96):?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit (cherry picked from commit 00a7c5e02c8f647f53b8ec88dae2896d31ab6ba8) --- themes/heo/components/AnalyticsCard.js | 12 ++++++++---- themes/heo/config.js | 6 ++++++ 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/themes/heo/components/AnalyticsCard.js b/themes/heo/components/AnalyticsCard.js index 835f4900917..a6c17e8816d 100644 --- a/themes/heo/components/AnalyticsCard.js +++ b/themes/heo/components/AnalyticsCard.js @@ -11,31 +11,35 @@ export function AnalyticsCard(props) { const today = new Date() const diffTime = today.getTime() - targetDate.getTime() // 获取两个日期之间的毫秒数差值 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 return <>
-
文章数:
+
{postCountTitle}
{postCount}
-
建站天数:
+
{siteTimeTitle}
{diffDays} 天
-
访问量:
+
{siteVisitTitle}
-
访客数:
+
{siteVisitorTitle}
diff --git a/themes/heo/config.js b/themes/heo/config.js index bd0353c3ccb..4a037982c56 100644 --- a/themes/heo/config.js +++ b/themes/heo/config.js @@ -122,6 +122,12 @@ const CONFIG = { HEO_SOCIAL_CARD_TITLE_3: '点击加入社群', 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, // 显示首页 From 02790ab8a36b4bb08cb350bf66f882c1cdb2a139 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sat, 28 Dec 2024 16:04:34 +0800 Subject: [PATCH 3/4] INLINE_CONFIG --- lib/notion/getNotionConfig.js | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index 637c73eae84..b8ba4cd1bef 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -162,7 +162,15 @@ export async function getConfigMapFromConfigPage(allPages) { } } } - return notionConfig + + + // 将INLINE_CONFIG合并,@see https://docs.tangly1024.com/article/notion-next-inline-config + const combine = Object.assign( + {}, + deepClone(notionConfig), + parseConfig(notionConfig?.INLINE_CONFIG) + ) + return combine } /** From f52fcaf1c0285564a6365e00fe1d14cd9637a179 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Sat, 28 Dec 2024 16:40:48 +0800 Subject: [PATCH 4/4] =?UTF-8?q?=E4=BF=9D=E7=95=99inline=5Fconfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/notion/getNotionConfig.js | 30 +++++++++++++++++++----------- 1 file changed, 19 insertions(+), 11 deletions(-) diff --git a/lib/notion/getNotionConfig.js b/lib/notion/getNotionConfig.js index b8ba4cd1bef..029c7b96b5d 100644 --- a/lib/notion/getNotionConfig.js +++ b/lib/notion/getNotionConfig.js @@ -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 } }