Merge pull request #905 from wdhongtw/hide-updated-time

feat(layout): add option for updated time of posts
pull/928/head
Ruipeng Zhang 2021-08-08 15:55:17 -04:00 committed by GitHub
commit 4ae91c1d1e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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 */}