From b272dbb395bbd1e18d61f0c7868ebddea0cf1f73 Mon Sep 17 00:00:00 2001 From: weidah Date: Sun, 8 Aug 2021 19:58:29 +0800 Subject: [PATCH] feat(layout): add option for updated time of posts Provides a new config option to determine whether to show updated time. In addition to true/false, we also support "auto" setting that shows updated time automatically when post updated time is different from post date. Signed-off-by: Weida Hong --- include/schema/common/article.json | 7 +++++++ layout/common/article.jsx | 5 ++++- 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/include/schema/common/article.json b/include/schema/common/article.json index 8794662..95cd75b 100644 --- a/include/schema/common/article.json +++ b/include/schema/common/article.json @@ -40,6 +40,13 @@ "default": true, "nullable": true }, + "update_time": { + "type": ["boolean", "string"], + "description": "Whether to show updated time. For \"auto\", shows article update time only when page.updated is set and it is different from page.date", + "default": true, + "enum": [true, false, "auto"], + "nullable": true + }, "licenses": { "$ref": "/misc/poly_links.json", "description": "Article licensing block", diff --git a/layout/common/article.jsx b/layout/common/article.jsx index 7c01d3d..8ae58a3 100644 --- a/layout/common/article.jsx +++ b/layout/common/article.jsx @@ -26,6 +26,9 @@ module.exports = class extends Component { const indexLaunguage = config.language || 'en'; const language = page.lang || page.language || config.language || 'en'; const cover = page.cover ? url_for(page.cover) : null; + const updateTime = article && article.update_time !== undefined ? article.update_time : true; + const isUpdated = page.updated && !moment(page.date).isSame(moment(page.updated)); + const shouldShowUpdated = page.updated && ((updateTime === 'auto' && isUpdated) || updateTime === true); return {/* Main content */} @@ -47,7 +50,7 @@ module.exports = class extends Component { __html: _p('article.created_at', ``) }}>} {/* Last Update Date */} - {page.updated && ${date(page.updated)}`) }}>} {/* author */}