From c48586252f89b72340abf47f0bc97cf5278071bb Mon Sep 17 00:00:00 2001 From: clode Date: Thu, 12 Apr 2018 18:06:47 +0800 Subject: [PATCH 01/10] [Optimization] Rewrite some code logic and method change 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/hexo-theme-next#223 --- _config.yml | 7 +++++-- layout/_macro/post.swig | 37 +++++++++++++++---------------------- 2 files changed, 20 insertions(+), 24 deletions(-) diff --git a/_config.yml b/_config.yml index fc83307c57..6e3caab1f2 100644 --- a/_config.yml +++ b/_config.yml @@ -264,8 +264,11 @@ post_meta: 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 + # 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 # Post wordcount display settings diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index 07635aa2d9..d94fd37973 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -73,11 +73,6 @@
- {% if theme.post_meta.date_time_merge %} - {% set datetime_format = config.date_format + ' ' + config.time_format %} - {% else %} - {% set datetime_format = config.date_format %} - {% endif %} {% if theme.post_meta.created_at %} From 4aaa0158ccaab6bef70b5c7e187dc57f8c9c5895 Mon Sep 17 00:00:00 2001 From: clode Date: Thu, 12 Apr 2018 22:22:05 +0800 Subject: [PATCH 02/10] Add missed method replacement and under line of time --- layout/_macro/post.swig | 6 +++--- source/css/_common/components/post/post-meta.styl | 4 ++++ 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index d94fd37973..02265545d6 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -81,8 +81,8 @@ {% if theme.post_meta.item_text %} {% endif %} - {% if theme.symbols_count_time.item_text_total %} - + {% endif %} - {# + {# #}{{ symbolsCountTotal(site) }}{# #} {% endif %} @@ -26,10 +26,10 @@ {% if theme.symbols_count_time.item_text_total %} - + {% endif %} - {# - #}{{ symbolsTimeTotal(site, theme.symbols_count_time.awl, theme.symbols_count_time.wpm) }}{# + {# + #}{{ symbolsTimeTotal(site, theme.symbols_count_time.awl, theme.symbols_count_time.wpm, __('symbols_count_time.time_minutes')) }}{# #} {% endif %}
From a482a37f3ad536b1f43daa8dea3212f45eb83859 Mon Sep 17 00:00:00 2001 From: clode Date: Sun, 15 Apr 2018 13:42:21 +0800 Subject: [PATCH 07/10] Add missed judgment in if statement --- layout/_macro/post.swig | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index bfeafe0373..7a06c573f8 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -75,7 +75,8 @@ {% set date_diff = date(post.date) != date(post.updated) %} - {% set datetime_diff = full_date(post.date) != full_date(post.updated) %} + {% set time_diff = time(post.date) != time(post.updated) %} + {% set datetime_diff = date_diff or time_diff %} {% if theme.post_meta.created_at %} {% if theme.post_meta.item_text %} - + {% endif %} - {% endif %} - {% if theme.post_meta.updated_at.enabled && date_diff %} - {% set display_updated = !theme.post_meta.updated_at.only_diff || theme.post_meta.updated_at.only_diff && datetime_diff %} + {% if theme.post_meta.updated_at.enabled && datetime_diff %} + {% set display_updated = !theme.post_meta.updated_at.another_day || theme.post_meta.updated_at.another_day && date_diff %} {% if display_updated or !theme.post_meta.created_at %} {% if theme.post_meta.created_at and theme.post_meta.updated_at.enabled %} From 9f4f0143aff6e7e804e3396f33acdcf9a109efd0 Mon Sep 17 00:00:00 2001 From: "Ivan.Nginx" Date: Sun, 15 Apr 2018 19:34:11 +0300 Subject: [PATCH 10/10] Final optimization for `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. --- _config.yml | 7 ++++--- layout/_macro/post.swig | 14 +++++++++----- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/_config.yml b/_config.yml index 07a93bab3c..82783dc7b2 100644 --- a/_config.yml +++ b/_config.yml @@ -263,9 +263,10 @@ post_meta: created_at: true updated_at: enabled: true - # Show updated date only if `updated date` different from 'created date'. If false, will show even if `updated time` have difference from 'created time'. - # Another words: show updated label only if post edited in another day than was created. - another_day: false + # 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 # Post wordcount display settings diff --git a/layout/_macro/post.swig b/layout/_macro/post.swig index 89f5372659..addab9555b 100644 --- a/layout/_macro/post.swig +++ b/layout/_macro/post.swig @@ -86,15 +86,15 @@ {% endif %} - {% if !date_diff && time_diff && theme.post_meta.updated_at.enabled %} + {% if !date_diff && time_diff && theme.post_meta.updated_at.enabled && theme.post_meta.updated_at.another_day %} {% set create_title = __('post.created') + __('symbol.colon') + full_date(post.date) + ' / ' + __('post.modified') + __('symbol.colon') + time(post.updated) %} {% else %} {% set create_title = __('post.created') + __('symbol.colon') + full_date(post.date) %} {% endif %} + #}{{ date(post.date) -}} + {% endif %} {% if theme.post_meta.updated_at.enabled && datetime_diff %} @@ -112,8 +112,12 @@ {% endif %} + #}{% if date_diff -%} + {{- date(post.updated) -}} + {%- else -%} + {{- time(post.updated) -}} + {%- endif -%} + {% endif %} {% endif %}