Skip to content

Comments

feat(layout): add option for updated time of posts#905

Merged
ppoffice merged 1 commit intoppoffice:masterfrom
wdhongtw:hide-updated-time
Aug 8, 2021
Merged

feat(layout): add option for updated time of posts#905
ppoffice merged 1 commit intoppoffice:masterfrom
wdhongtw:hide-updated-time

Conversation

@wdhongtw
Copy link

@wdhongtw wdhongtw commented Aug 8, 2021

If the post's updated is same as date, hide the element of
updated time automatically.

Also provides a new config option to toggle this behavior.

Signed-off-by: Weida Hong wdhongtw@gmail.com

@wdhongtw
Copy link
Author

wdhongtw commented Aug 8, 2021

This content of the PR is useful when some user has updated_option: 'date' in the Hexo configuration.
(Most posts may have the same date and updated information.)

Considering theme users may relay on existing behavior, the hiding feature in this PR is only active if the user set
article.updated_auto_hide: true explicitly in theme configuration.

Please let me know if we can/should change the default behavior.
Also, let me know if I need up update the documentation. :D

Copy link
Owner

@ppoffice ppoffice left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's default the behavior to always show article update time. And it would be great if you can update the docs as well.

"default": true,
"nullable": true
},
"updated_auto_hide": {
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about replace update_auto_hide with update_time and allow true, false, "auto" as acceptable values?

  • true: always show article update time when page.updated is set.
  • false: always hide article update time.
  • "auto": show article update time only when page.updated is set and it is different from page.date.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good idea! :D

const { url_for, date, date_xml, __, _p } = helper;

const indexLaunguage = config.language || 'en';
const skip_same_date = config.article.updated_auto_hide || false;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Variable names should be camelCase instead of snake_case.

}}></span>}
{/* Last Update Date */}
{page.updated && <span class="level-item" dangerouslySetInnerHTML={{
{page.updated && !(skip_same_date && moment(page.date).isSame(moment(page.updated))) && <span class="level-item" dangerouslySetInnerHTML={{
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better to set up a new variable for !(skip_same_date && moment(page.date).isSame(moment(page.updated))) so this statement can be cleaner.

const updateTime = article ? article.update_time : true;
const isUpdated = page.updated && !moment(page.date).isSame(moment(page.updated));
const showUpdateTime = page.updated && ((updateTime === 'auto' && isUpdated) || updateTime === true);

@wdhongtw wdhongtw force-pushed the hide-updated-time branch from 4a18fd6 to 11bf259 Compare August 8, 2021 18:59
@wdhongtw wdhongtw changed the title feat(layout): hide updated time automatically feat(layout): add option for updated time of posts Aug 8, 2021
@wdhongtw
Copy link
Author

wdhongtw commented Aug 8, 2021

According to reviewer's suggestion, modify the design of this PR as follows:

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.

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>
@wdhongtw wdhongtw force-pushed the hide-updated-time branch from 11bf259 to b272dbb Compare August 8, 2021 19:36
@ppoffice ppoffice merged commit 4ae91c1 into ppoffice:master Aug 8, 2021
@wdhongtw wdhongtw deleted the hide-updated-time branch August 9, 2021 03:57
@wdhongtw
Copy link
Author

wdhongtw commented Aug 9, 2021

Thanks for merge. :D

I will submit another PR for the document site after next release (maybe 4.5.0 or 4.4.1).

@ppoffice
Copy link
Owner

ppoffice commented Aug 9, 2021

@wdhongtw It's already done.

bibitchhetri pushed a commit to bibitchhetri/hexo-theme-icarus that referenced this pull request May 27, 2025
feat(layout): add option for updated time of posts
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants