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 <wdhongtw@gmail.com>
pull/905/head
weidah 2021-08-08 19:58:29 +08:00 committed by Weida Hong
parent f0305775f9
commit b272dbb395
No known key found for this signature in database
GPG Key ID: 8CC2E9CFB3BE270C
2 changed files with 11 additions and 1 deletions

View File

@ -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",

View File

@ -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 <Fragment>
{/* Main content */}
@ -47,7 +50,7 @@ module.exports = class extends Component {
__html: _p('article.created_at', `<time dateTime="${date_xml(page.date)}" title="${new Date(page.date).toLocaleString()}">${date(page.date)}</time>`)
}}></span>}
{/* Last Update Date */}
{page.updated && <span class="level-item" dangerouslySetInnerHTML={{
{shouldShowUpdated && <span class="level-item" dangerouslySetInnerHTML={{
__html: _p('article.updated_at', `<time dateTime="${date_xml(page.updated)}" title="${new Date(page.updated).toLocaleString()}">${date(page.updated)}</time>`)
}}></span>}
{/* author */}