From 7e79987795ca1c4ef7cbbe70fad36428e4e6408c Mon Sep 17 00:00:00 2001 From: anime Date: Mon, 7 Jul 2025 00:42:03 +0800 Subject: [PATCH 1/3] feat(ArticleExpirationNotice): implement ArticleExpirationNotice component - Add ArticleExpirationNotice component to the page layout in Heo theme resolve #2738 --- components/ArticleExpirationNotice.js | 73 +++++++++++++++++++++++++++ themes/heo/index.js | 4 +- 2 files changed, 76 insertions(+), 1 deletion(-) create mode 100644 components/ArticleExpirationNotice.js diff --git a/components/ArticleExpirationNotice.js b/components/ArticleExpirationNotice.js new file mode 100644 index 00000000..ce046313 --- /dev/null +++ b/components/ArticleExpirationNotice.js @@ -0,0 +1,73 @@ +import { siteConfig } from '@/lib/config' + +/** + * 文章过期提醒组件 + * 当文章超过指定天数时显示提醒 + * @param {Object} props - 组件属性 + * @param {Object} props.post - 文章数据 + * @param {number} [props.daysThreshold=90] - 过期阈值(天) + * @returns {JSX.Element|null} + */ +export default function ArticleExpirationNotice({ + post, + daysThreshold = siteConfig('ARTICLE_EXPIRATION_DAYS', 90) +}) { + const articleExpirationEnabled = siteConfig( + 'ARTICLE_EXPIRATION_ENABLED', + false + ) + if (!articleExpirationEnabled || !post?.lastEditedDay) { + return null + } + + const postDate = new Date(post.lastEditedDay) + const today = new Date() + const diffTime = Math.abs(today - postDate) + const daysOld = Math.ceil(diffTime / (1000 * 60 * 60 * 24)) + const isVisible = daysOld >= daysThreshold + + if (!isVisible) { + return null + } + + // 使用 %%DAYS%% 作为占位符 + const articleExpirationMessage = siteConfig( + 'ARTICLE_EXPIRATION_MESSAGE', + '这篇文章发布于 %%DAYS%% 天前,内容可能已过时,请谨慎参考。' + ) + const articleExpirationMessageParts = + articleExpirationMessage.split('%%DAYS%%') + + // 直接返回 JSX 内容 + return ( +
+
+ +
+
+ {siteConfig('ARTICLE_EXPIRATION_TITLE', '温馨提醒')} +
+
+ + + {(() => { + return ( + <> + {articleExpirationMessageParts[0]} + + {daysOld} + + {articleExpirationMessageParts[1]} + + ) + })()} + +
+
+
+
+ ) +} diff --git a/themes/heo/index.js b/themes/heo/index.js index 6fa85552..ab779940 100644 --- a/themes/heo/index.js +++ b/themes/heo/index.js @@ -43,6 +43,7 @@ import SideRight from './components/SideRight' import CONFIG from './config' import { Style } from './style' import AISummary from '@/components/AISummary' +import ArticleExpirationNotice from '@/components/ArticleExpirationNotice' /** * 基础布局 采用上中下布局,移动端使用顶部侧边导航栏 @@ -307,7 +308,8 @@ const LayoutSlug = props => {
- + + {post && } From c02a94c923d586f1cc99c73d5731c7ae35a4a907 Mon Sep 17 00:00:00 2001 From: anime Date: Mon, 7 Jul 2025 00:46:21 +0800 Subject: [PATCH 2/3] feat(config): add article expiration reminder configuration - Added ARTICLE_EXPIRATION_DAYS to configure expiration threshold - Added ARTICLE_EXPIRATION_MESSAGE to set custom expiration message - Added ARTICLE_EXPIRATION_ENABLED to control whether enable this feature --- conf/post.config.js | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/conf/post.config.js b/conf/post.config.js index 3e7a4ff3..8c987625 100644 --- a/conf/post.config.js +++ b/conf/post.config.js @@ -28,6 +28,16 @@ module.exports = { POST_RECOMMEND_COUNT: process.env.NEXT_PUBLIC_POST_RECOMMEND_COUNT || 6, // 推荐文章数量 POSTS_PER_PAGE: process.env.NEXT_PUBLIC_POST_PER_PAGE || 12, // post counts per page POSTS_SORT_BY: process.env.NEXT_PUBLIC_POST_SORT_BY || 'notion', // 排序方式 'date'按时间,'notion'由notion控制 + + // 文章过期提醒配置 + ARTICLE_EXPIRATION_DAYS: + process.env.NEXT_PUBLIC_ARTICLE_EXPIRATION_DAYS || 90, // 文章过期提醒阈值(天) + ARTICLE_EXPIRATION_MESSAGE: + process.env.NEXT_PUBLIC_ARTICLE_EXPIRATION_MESSAGE || + '这篇文章发布于 %%DAYS%% 天前,内容可能已过时,请谨慎参考。', // 过期提示信息,使用 %%DAYS%% 作为天数占位符 + ARTICLE_EXPIRATION_ENABLED: + process.env.NEXT_PUBLIC_ARTICLE_EXPIRATION_ENABLED || 'false', // 是否启用文章过期提醒 + POST_WAITING_TIME_FOR_404: process.env.NEXT_PUBLIC_POST_WAITING_TIME_FOR_404 || '8', // 文章加载超时时间,单位秒;超时后跳转到404页面 From c439810fa25eb8509278539c26fcf407316d2ae3 Mon Sep 17 00:00:00 2001 From: tangly1024 Date: Mon, 7 Jul 2025 15:11:16 +0800 Subject: [PATCH 3/3] Update post.config.js --- conf/post.config.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/conf/post.config.js b/conf/post.config.js index 8c987625..1922196c 100644 --- a/conf/post.config.js +++ b/conf/post.config.js @@ -29,7 +29,7 @@ module.exports = { POSTS_PER_PAGE: process.env.NEXT_PUBLIC_POST_PER_PAGE || 12, // post counts per page POSTS_SORT_BY: process.env.NEXT_PUBLIC_POST_SORT_BY || 'notion', // 排序方式 'date'按时间,'notion'由notion控制 - // 文章过期提醒配置 + // 文章过期提醒配置 p.s. 目前此功能暂时只适用于heo主题 ARTICLE_EXPIRATION_DAYS: process.env.NEXT_PUBLIC_ARTICLE_EXPIRATION_DAYS || 90, // 文章过期提醒阈值(天) ARTICLE_EXPIRATION_MESSAGE: