Skip to content

[Optimization] Rewrite some code logic and method change for post_meta.updated_at option.#228

Merged
ivan-nginx merged 12 commits intotheme-next:masterfrom
jackey8616:date_time_merge
Apr 15, 2018
Merged

[Optimization] Rewrite some code logic and method change for post_meta.updated_at option.#228
ivan-nginx merged 12 commits intotheme-next:masterfrom
jackey8616:date_time_merge

Conversation

@jackey8616
Copy link
Contributor

Accidentally close previous PR, sorry..

PR Checklist

Please check if your PR fulfills the following requirements:

  • The commit message follows our guidelines.
  • Tests for the changes have been added (for bug fixes / features).
    • Muse | Mist have been tested.
    • Pisces | Gemini have been tested.
  • Docs have been added / updated (for bug fixes / features).

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?

With NexT _config.yml setting:

post_meta:
  ...
  date_time_merge: true
  ...

In every post
ex create time is 2018-01-01 08:00:00 edite time is 2018-01-01 10:00:00

Posted on 2018-01-01 08:00:00 | Post modified: 2018-01-01 10:00:00

But with this _config.yml setting:

date_time_merge: false

updated_diff would not check by date and time but only date.

Posted on 2018-01-01 08:00:00

What is the new behavior?

By changing check statement from date to datetime.
_config.yml no longer need date_time_merge field, default will be check by also date and time.
with default new filed in _config.yml setting:

post_meta:
  ...
  # If set this option, the updated_diff will check diff base on this format.
  # Leave empty will check by both date and time.
  updated_diff_check_format:
  # Leave empty will use default hexo date_formt + ' ' + time_format for every post.
  datetime_format:
  ...

Posted on 2018-01-01 08:00:00 | Post modified: 2018-01-01 10:00:00

updated_diff_check_format: YYYY-MM-DD HH
datetime_format:

Posted on 2018-01-01 08:00:00 | Post modified: 2018-01-01 10:00:00

updated_diff_check_format: YYYY-MM-DD HH
datetime_format: YYYY-MM-DD HH a

Posted on 2018-01-01 08 am| Post modified: 2018-01-01 10 am

How to use?

The default setting is empty, so the check and render all using full format.
And this may effect some users who want to only resent YYYY-MM-DD
By setting datetime_format to YYYY-MM-DD than everything won't be effect but only checking format.

post_meta:
  ...
  # If set this option, the updated_diff will check diff base on this format.
  # Leave empty will check by both date and time.
  updated_diff_check_format:
  # Leave empty will use default hexo date_formt + ' ' + time_format for every post.
  datetime_format:
  ...

and yes, it works!

Does this PR introduce a breaking change?

  • Yes.
  • No.

    Original updated_diff checking method changed
    From date(new Date(), [format])
    To full_date(new Date(), [format])
    For full datetime checking.

    Also merge some excess if statement.
    References theme-next#223
@ivan-nginx
Copy link
Member

ivan-nginx commented Apr 12, 2018

As from user point of view if just turn on updated_diff: true:

# Post meta display settings
post_meta:
  item_text: true
  created_at: true
  updated_at: true
  categories: true
  # Only show 'updated' if different from 'created'.
  updated_diff: true
  # If set this option, the updated_diff will check diff base on this format.
  # Leave empty will check by both date and time.
  updated_diff_check_format:
  # Leave empty will use default hexo date_formt + ' ' + time_format for every post.
  datetime_format:

And see this:

image

Post modified: 2017-10-03 07:02:31

I think user don't want to see time (07:02:31) if dates already have different (2017-09-20 vs 2017-10-03).


  1. Need to saw time's different's only if dates have no diffs.
  2. Need to add description in configs. As for user, i don't understand what they meaning. I just turn on updated_diff option and don't understand what i can do with outher 2 options below. Maybe need to add descriptions with examples in config?
  3. Keep it simple. As simplest as u can.

Also, i think need to make some refactors in this updated options, for example:

Instead of this:

post_meta:
  item_text: true
  created_at: true
  updated_at: false
  # Only show 'updated' if different from 'created'.
  updated_diff: false
  # If set this option, the updated_diff will check diff base on this format.
  # Leave empty will check by both date and time.
  updated_diff_check_format:
  # Leave empty will use default hexo date_formt + ' ' + time_format for every post.
  datetime_format:
  categories: true

Do this:

post_meta:
  item_text: true
  created_at: true
  updated_at:
    enable: false
    # Only show 'updated' if different from 'created'.
    updated_diff: false
    # If set this option, the updated_diff will check diff base on this format.
    # Leave empty will check by both date and time.
    updated_diff_check_format:
    # Leave empty will use default hexo date_formt + ' ' + time_format for every post.
    datetime_format:
  categories: true

@jackey8616
Copy link
Contributor Author

Totally agree with the idea about ' keeping simple'.

With time display style, here is some idea that comes out of my mind.

  1. When create and updated date is same, but time is different, display date & time in create but only time in update.
    ex created 2018-01-01 08:00:00 updated 2018-01-01 10:00:00

Posted on 2018-01-01 08:00:00 | Post modified 10:00:00

  1. When create and updated date is different, display only date.
    ex created 2018-01-01 08:00:00 updated 2018-01-02 10:00:00

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

  1. Left custom format is still work but write 1. and 2. just display it.
    but 3. one is need to be more concern about it.
    or maybe just cancel the field provide to user and let people use 1. or 2.

After all, the final _config.yml will look like:

post_meta:
  ...
  updated_at:
    enable: false
    # Only show 'updated' if different from 'created'.
    updated_diff: false
    # If set this option, the updated_diff will check diff base on this format.
    # Leave empty will check by both date and time.
    diff_check_format:
  ...

or maybe it have other features needs more filed.

@ivan-nginx
Copy link
Member

ivan-nginx commented Apr 12, 2018

1 and 2 what u are suggested is fine, yep. That's what i'm talking about in my 1st suggest.

Posted on 2018-01-01 08:00:00 | Post modified 10:00:00

But maybe it can be improved with something like:

Posted on Today 08:00:00 | Post modified Today 10:00:00

?

Or just like that:

Posted on 2018-01-01 08:00:00 | Post modified Today 10:00:00

OR! And this is best variant as for me:

  1. Posted on 2018-01-01 | Post modified Today.
  2. When user will navigate with mouse on this items, popup (title) will show full date & time.

Need to appear as little digits as possible on main pages. But if user want to see details, he can do it, right?


post_meta:
  ...
  updated_at:
    enable: false
    # Only show 'updated' if different from 'created'.
    updated_diff: false
    # If set this option, the updated_diff will check diff base on this format.
    # Leave empty will check by both date and time.
    diff_check_format:
  ...

Yep! That's seems good for me. But i still don't understand diff_check_format option. (I'm understand, but user will feel like that)

@jackey8616
Copy link
Contributor Author

jackey8616 commented Apr 12, 2018

popping bubble of full datetime format is a fascinated idea! and i just commited with it!
add some style for time HTML tag.

Im think that why not just let created time also shows Today or not.
like :

# create / updated at same day.
Posted at (2018-01-01 or Today) 08:00 | modified at 10:00
# create / updated same day but different time. ( maybe without same day)
Posted at 2018-01-01 08:00 | modified at (same day) 10:00
# both date and time are different.
Posted at 2018-01-01 08:00 | modified at 2018-01-02 10:00

about _config.yml, i think the meaning of customize is not so important.
maybe just back to simple update_diff and no more format setting.

post_meta:
  item_text: true
  created_at: true
  updated_at:
    enable: false
    # Only show 'updated' if different from 'created'.
    updated_diff: false
  categories: true

or you think we should keep customize setting.
and find something more flexible and simple way to invoke?

@ivan-nginx
Copy link
Member

ivan-nginx commented Apr 12, 2018

or you think we should keep customize setting.

  1. I think date and time format can be defined in Hexo, not in theme. So, no need this setting.
    post_meta:
      item_text: true
      created_at: true
      updated_at:
        enable: false
        # Only show 'updated' if different from 'created'.
        updated_diff: false
      categories: true
    This settings seem's good, yeah!
  2. About first suggest don't understand where u want set it (in main or in title).

I think u can make commits and we will see to the way of the road how to look's that. Anyway, this is important option and no need to do this fast. Release of 6.2.0 will in April 15, so, we have a lot of time to improve this feature.


ADDED: if we will show full date / time in titles, no need to create «Today» translate i think.
I mean, see:

If post was changed today, in title we can show:
On Posted on link — Post created: 2018-01-01 08:00 — with defined format from Hexo
On Modified link — Post modified: 2018-01-01 10:00 — with defined format from Hexo

And in meta we just keep maximum old / default style, like:

Posted on 2018-01-01 | Modified 2018-01-02 — if different DAYS.
Posted on 2018-01-01 — if same DAYS — and in this titlePost created: 2018-01-01 08:00 | Post modified: 2018-01-01 10:00.

@jackey8616
Copy link
Contributor Author

Oh, i have already committed,
maybe you can see on my site.

i added a under line at created and modified time for more user notice,
and hover to it. the popping bubble will shows detail time.

@ivan-nginx
Copy link
Member

image

Many digits. Need to keep simpler, see my previous comment.

@jackey8616
Copy link
Contributor Author

jackey8616 commented Apr 12, 2018

i haven't remove the very begin's commit content about datetime_format:
this commit is just for showing under line and popping bubble 😆

later i will working on reducing digits.

@ivan-nginx
Copy link
Member

later i will working on reducing digits.

Yeah, need to keep maximum web space, i know. Keep it maximum simpler.

@jackey8616
Copy link
Contributor Author

Saw your ADDED,
About popping bubble.
Only showing Posted on and Modified at text at title,
OR
Showing Posted on (datetime) / Modified at (datetime) ?
i only sure about
hover onto it shows bubble with full datetime format(hexo full_date() function with hexo format).
i got bad understanding ... sorry. 😭

and quiet not understand with:

Posted on 2018-01-01 — if same DAYS — and in this title — Post created: 2018-01-01 08:00 | Post modified: 2018-01-01 10:00.
what ** in this title** means?

if same DAYS, output both date and time like this ?
Posted on 2018-01-01 08:00 | modified at 2018-01-01 10:00

@ivan-nginx
Copy link
Member

Showing Posted on (datetime) / Modified at (datetime) ?

Yeah, just like that.

if same DAYS, output both date and time like this ?

If same days, no need output «Modified». Only Posted on 2018-01-01 and then mouse over on label 2018-01-01, show in title Posted on (datetime) / Modified at (datetime).

I think any post created can be modified many times in one day, for example. So, it is some stupid to show «Modified» every time on every post with updated_diff option enabled. This option was created for this, for not show «Modified» label for one-day-created posts, and if we will show in each post «Modified» label, this option does not make sense.

@jackey8616
Copy link
Contributor Author

jackey8616 commented Apr 13, 2018

i got you!
In every post only shows created time,
and if the post have updated time,
they all put into popping bubble, is that right?

show in title means HTML time tag's title attribute 🤣

DIFF DAYS => show both create / update time in post meat
SAME DAYS => show only create time in post meta, but updated time in bubble.

i'm also wondering every time i saved a .md that modified time will be change,
is kind of annoying..

@ivan-nginx
Copy link
Member

Title = Bubble, yes! It also called popup.

i'm also wondering every time i saved a .md that modified time will be change,
is kind on annoying..

It make Hexo, we can't do anything here with this. We only can display it or not.

@jackey8616
Copy link
Contributor Author

@ivan-nginx i have already make some changes on showing datetime,
and also removed _config.yml filed which this PR added at very first beginning.

you can also find some preview on my site
There are two post shows the changes under SAME DAYS and DIFF DAYS.

and here is something needs more opinion about:
When SAME DAYS, in the popup, the text seems a little duplicate on word 'POST'
and maybe we can add another text called modify: Modified
ex created 2018-01-01 08:00:00 update 2018-01-01 10:00:00
shows

created 2018-01-01 08:00:00 / modified 10:00:00

@ivan-nginx
Copy link
Member

Yeah, seem's good.
I'll check code a little later.

}

time {
border-bottom: 1px solid $grey-dark;
Copy link
Member

Choose a reason for hiding this comment

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

MB no need this styles?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

i was thinking MB a underline would helping user's to notice that there is more info about time.
not underline but MB something else would not confuse with href link.

Copy link
Member

Choose a reason for hiding this comment

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

Yeah, need to think about it, but underline seems like it's hyperlink and really do some confuse. 😃

Copy link
Contributor Author

Choose a reason for hiding this comment

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

MB we can replace solid to dotted?

Copy link
Member

Choose a reason for hiding this comment

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

Try it.

Copy link
Member

Choose a reason for hiding this comment

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

Or better dotted?
Try to play around with this: https://www.w3schools.com/cssref/pr_border-bottom_style.asp

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I use dashed.
Done! and take a look!

ivan-nginx and others added 2 commits April 15, 2018 13:43
1. Modified default settings: AWL = 4; WPM = 275.
2. Added suffix as string parameter if time to read less then 60 minutes. Default: 'mins.'
3. Refactored language translates.
@jackey8616
Copy link
Contributor Author

@ivan-nginx i have already push the latest stuff about underline style and popup.
take a look!
DIFF_DAY_SAME_TIME and SAME_DAY_SAME_TIME
SAME_DAY_DIFF_TIME

@ivan-nginx
Copy link
Member

Yeah! For now seem's pefect. I'll edit it a little.

@ivan-nginx
Copy link
Member

ivan-nginx commented Apr 15, 2018

Alright, i test it and there is some bugs: if i turn off updated_diff option or turn it on — there is nothing changes.

I suggest what with updated_diff option enabled updated date must appear always as created date, even if only time is change (like in TEST-DIFF-DAY-SAME-TIME). But with turned updated_diff option on — it is fine for now, as we can see here. So, updated_diff option must have weight with this conditions.

1. Replaced `updated_diff` by `only_diff` and set it under suboption: `updated_at.only_diff`.
1. If true, show updated date label only if `updated date` different from 'created date' (post edited in another day than was created). And if post will edited in same day as created, edited time will show in popup title under created time label.
2. If false show anyway, but if post edited in same day, show only edited time.
@ivan-nginx
Copy link
Member

ivan-nginx commented Apr 15, 2018

  • Replaced updated_diff by another_day option. For now config changes is:

    post_meta:
      item_text: true
      created_at: true
    - updated_at: false
    - # Only show 'updated' if different from 'created'.
    - updated_diff: false
    - # If true, post's time format will be hexo config's date_format + ' ' + time_format.
    - date_time_merge: false
    post_meta:
      item_text: true
      created_at: true
      updated_at:
        enabled: true
        # If true, show updated date label only if `updated date` different from 'created date' (post edited in another day than was created).
        # And if post will edited in same day as created, edited time will show in popup title under created time label.
        # If false show anyway, but if post edited in same day, show only edited time.
        another_day: true
      categories: true
  • another_day option:

    1. If true, show updated date label only if updated date different from created date (post edited in another day than was created). And if post will edited in same day as created, edited time will show in popup title under created time label.
    2. If false show anyway, but if post edited in same day, show only edited time.
  • Added «Edited on» translated label in accordance with Update the post modify text for unification #232 pull.

@ivan-nginx ivan-nginx changed the title [Optimization] Rewrite some code logic and method change [Optimization] Rewrite some code logic and method change for post_meta.updated_at option. Apr 15, 2018
@ivan-nginx ivan-nginx merged commit 2768e5f into theme-next:master Apr 15, 2018
@jackey8616 jackey8616 deleted the date_time_merge branch April 16, 2018 05:15
edited: Edited on
created: Created
modified: Modified
edit: Edit this post
Copy link
Collaborator

@sli1989 sli1989 Apr 16, 2018

Choose a reason for hiding this comment

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

I recommend for its display like Creation time: 2018-4-16 18:25:03 in popup annotation.

+  created: Creation time
+  modified: Modification time

Copy link
Member

@ivan-nginx ivan-nginx Apr 16, 2018

Choose a reason for hiding this comment

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

I think no need long labels here. When user move mouse under the date, he understand what he see date/time of post creation/modification.
So, Created: 2018-04-14 12:51:10 / Modified: 23:00:00 — look's fine i think.

@sli1989
Copy link
Collaborator

sli1989 commented May 16, 2018

one thing seems strange.

1

it was updated in 2018-5-12, but today it's 2018-5-16, but shows time only today.
maybe need to add compare condition with the present time .


no, but it's static...
well, re-considerate the date_diff.

{% set date_diff = date(post.date) != date(post.updated) %}

@sli1989 sli1989 mentioned this pull request May 21, 2018
15 tasks
tongluyang pushed a commit to tongluyang/hexo-theme-next that referenced this pull request Nov 19, 2019
[Optimization] Rewrite some code logic and method change for `post_meta.updated_at` option.
stevenjoezhang referenced this pull request in next-theme/hexo-theme-next Aug 17, 2020
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.

3 participants