Skip to content

Adds updated_diff option to post_meta#50

Merged
ivan-nginx merged 5 commits intotheme-next:masterfrom
SafeEval:updated-diff
Jan 19, 2018
Merged

Adds updated_diff option to post_meta#50
ivan-nginx merged 5 commits intotheme-next:masterfrom
SafeEval:updated-diff

Conversation

@SafeEval
Copy link

When post_meta.updated_at is enabled, all posts show a modification date,
even when it is the same as the creation date. The post_meta.updated_diff
flag only displays the modification date if it is different than the
creation date.

PR Type

What kind of change does this PR introduce?

  • Bugfix.
  • Feature.
  • Code style update (formatting, local variables).
  • Refactoring (no functional changes, no api changes).
  • Build related changes.
  • CI related changes.
  • Documentation content changes.
  • Other... Please describe:

What is the current behavior?

When post_meta.updated_at is enabled, posts will always show a modification date, even when it is the same as the creation date.

Example:

# _config.yml

post_meta:
  created_at: true
  updated_at: true

Result:

Posted on 2018-01-18 | Post modified: 2018-01-18

What is the new behavior?

If both updated_at and updated_diff are true, then the modified date will only be displayed if different from the creation date.

If updated_diff is false (default), then behavior is unchanged.

How to use?

In NexT _config.yml:

post_meta:
  created_at: true
  updated_at: true
  updated_diff: true

In a post's meta data:

date: 2018-01-18
updated: 2018-01-18

Result:

Posted on 2018-01-18


In a post's meta data:

date: 2018-01-18
updated: 2018-01-19

Result:

Posted on 2018-01-18 | Post modified: 2018-01-19

Does this PR introduce a breaking change?

  • Yes.
  • No.

When 'post_meta.updated_at' is enabled, all posts show a modification date,
even when it is the same as the creation date. The 'post_meta.updated_diff'
flag only displays the modification date if it is different than the
creation date.
{% endif %}

{% if theme.post_meta.updated_at %}
{% if display_updated %}
Copy link
Contributor

Choose a reason for hiding this comment

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

It will cause problems when the user choose only to show the updated_at and not the created_at.

Copy link
Author

Choose a reason for hiding this comment

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

You're right, thanks. Just revised and verified expected behavior with created_at, updated_at, and updated_diff, by themselves and together.

{% endif %}
{% endif %}

{% if display_updated %}
Copy link
Contributor

@tsanie tsanie Jan 19, 2018

Choose a reason for hiding this comment

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

Good jobs, I'd like this feature. 👍

But I think here {% if display_updated %} should be {% if theme.post_meta.updated_at && (display_updated || !theme.post_meta.created_at) %}, otherwise any datetime would not be shown when the article's created time equals its updated time and the created_at == false and updated_at == true and updated_diff == true

PS: this config is not normalize but I think it could be a situation. (on the test-case? 😃)

Copy link
Member

Choose a reason for hiding this comment

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

theme.post_meta

# Post meta display settings
post_meta:
  item_text: true
  created_at: true
  updated_at: false
  categories: true

This is default configuration.

Copy link
Member

@ivan-nginx ivan-nginx left a comment

Choose a reason for hiding this comment

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

Must be:

  1. If there is created and updated equal, then show only created.
  2. If there is created and updated not equal, show as it:
    2.1. If updated section in config enabled, then show created & updated.
    2.2. If not enabled, show only created.

@SafeEval
Copy link
Author

@tsanie: It's good to be thorough and cover all possible configurations. Now it only displays the updated datetime when created_at: false and updated_at: true, for both equal and unequal created/updated datetimes.

@ivan-nginx: correct, that is how it works, plus a couple additional cases.

All 8 possible cases have been verified to work as expected. When update_diff: true, then:

  1. If date: 2018-01-01, updated: 2018-01-01 (equal):
    1.1. If created_at: true, updated_at: true, then result:

    Posted on 2018-01-01

    1.2. If created_at: true and updated_at: false, then:

    Posted on 2018-01-01

    1.3. If created_at: false and updated_at: true, (pointed out by @tsanie) then:

    Post modified: 2018-01-02

    1.4. If created_at: false and updated_at: false, then:

    Nothing

  2. If date: 2018-01-01, updated: 2018-01-02 (unequal):
    2.1. If created_at: true and updated_at: true, then:

    Posted on 2018-01-01 | Post modified: 2018-01-02

    2.2. If created_at: true and updated_at: false, then:

    Posted on 2018-01-01

    2.3. If created_at: false and updated_at: true, (pointed out by @tsanie) then:

    Post modified: 2018-01-02

    2.4. If created_at: false and updated_at: false, then:

    Nothing

@ivan-nginx
Copy link
Member

@HuntedCodes how u not brake your brain with this cases? 😃
So, all tested, worked and can be merged?

<span class="post-meta-divider">|</span>
{% set date_updated_diff = date(post.date, config_date_format) != date(post.updated, config.date_format) %}
{% if theme.post_meta.updated_at %}
{% if !theme.post_meta.updated_diff || theme.post_meta.updated_diff && date_updated_diff %}
Copy link
Member

@ivan-nginx ivan-nginx Jan 19, 2018

Choose a reason for hiding this comment

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

One excess space before date_updated_diff string here.

Copy link
Author

Choose a reason for hiding this comment

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

Fixed the whitespace, and everything was tested.

@SafeEval
Copy link
Author

SafeEval commented Jan 19, 2018

@ivan-nginx a lot of coffee, and good sleep 😴😴😴😴 ☕️ ☕️ ☕️ ☕️

@ivan-nginx
Copy link
Member

Well, at the end of this day i think need a little beer. 🍺 😈

@ivan-nginx ivan-nginx merged commit 10ff86d into theme-next:master Jan 19, 2018
@ivan-nginx ivan-nginx added this to the v6.0.2 milestone Jan 19, 2018
@SafeEval
Copy link
Author

Beer is for merge conflicts lol

@SafeEval SafeEval deleted the updated-diff branch January 19, 2018 18:22
@ivan-nginx
Copy link
Member

Sometimes it bring fresh ideas and give another point of view on different things.
But sometimes give a little angry or misunderstanding, yes.

tongluyang pushed a commit to tongluyang/hexo-theme-next that referenced this pull request Nov 19, 2019
Adds updated_diff option to post_meta
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants