Skip to content

Add date_time_merge filed into post_meta#223

Merged
ivan-nginx merged 1 commit intotheme-next:masterfrom
jackey8616:date_time_merge
Apr 11, 2018
Merged

Add date_time_merge filed into post_meta#223
ivan-nginx merged 1 commit intotheme-next:masterfrom
jackey8616:date_time_merge

Conversation

@jackey8616
Copy link
Contributor

@jackey8616 jackey8616 commented Apr 10, 2018

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?

Without origin hexo and NexT _config.yml  

In post time area, only display with date. like below

Posted on 2018-04-10

What is the new behavior?

# hexo _config.yml
date_format: YYYY-MM-DD
time_format: HH:mm:ss
# NexT _config.yml
post_meta:
  ...
  date_time_merge: true
  ...

It can merge hexo config's date and time format together. like:

Posted on 2018-04-10 19:44:03

  • Screens with this changes: N/A
  • Link to demo site with this changes: MyGithubPage

How to use?

In NexT _config.yml:

post_meta:
  ...
  date_time_merge: true
  ...

and everything worked.

Does this PR introduce a breaking change?

  • Yes.
  • No.

With some of user may want post's show time can display to second.
So make a flag to switch it.

if flag is true, the display format will merge date, time together and seperate by a space.
for example:
in hexo _config.yml

date_format: YYYY-MM-DD
time_format: HH:mm:ss

in next _config.yml
post_meta:
  ...
  date_time_merge: true
  ...

final format will be 'YYYY-MM-DD HH:mm:ss'
@ivan-nginx ivan-nginx added this to the v6.2.0 milestone Apr 11, 2018
@ivan-nginx ivan-nginx merged commit 8043ed1 into theme-next:master Apr 11, 2018
@ivan-nginx
Copy link
Member

Thank's! 👍

@jackey8616
Copy link
Contributor Author

@ivan-nginx wow, waht a fast merge! thx for your approve.
to be honest, this PR is for fixing the updated_diff which in #50 .
i found that the if statement only check for date without time.
so i think why not just make it check with date and time.

and that's this merge made for.

couple of hours ago, i was wondering that the code seems not so good for the purpose of "checking with date time". i think i accendently

accidentally bind the check and output format.
i think i will fix this part of code to make it more logical.

<!-- layout/_macro/post.swig#L85 -->
            {% 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 %}
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              {% if theme.post_meta.item_text %}
                <span class="post-meta-item-text">{{ __('post.posted') }}</span>
              {% endif %}
              <time title="{{ __('post.created') }}" itemprop="dateCreated datePublished" datetime="{{ moment(post.date).format() }}">{#
              #}{{ date(post.date, datetime_format) }}{#
            #}</time>
            {% endif %}

            {% set date_updated_diff = date(post.date, datetime_format) != date(post.updated, datetime_format) %}
>>>>>>>>>>>>>> The check should run at full format for more precisely.
            {% if theme.post_meta.updated_at %}
              {% if !theme.post_meta.updated_diff || theme.post_meta.updated_diff && date_updated_diff %}
                {% set display_updated = true %}
              {% endif %}
            {% endif %}

i will try to edit this part again for a better program logic improve.
thx again for your RP.

@ivan-nginx
Copy link
Member

ivan-nginx commented Apr 11, 2018

Yeah, i understand, it's clever: fix for one-day diffs option posting and in same time add a feature!
2 rabbits at one shot commit. 😄
Good. Any similar pulls are welcome!

@ivan-nginx
Copy link
Member

@jackey8616 also, mb this can be important for improve this pull in future.

@jackey8616
Copy link
Contributor Author

@ivan-nginx this looks really good that we can even provide a datetime field for posts.
But hexo's official template engine is ejs, NexT is swig, im wondering is that any solutions for merging it.

if anything helps, plz tell me, even some keyword.
im eager to done with this part. 😃

@ivan-nginx
Copy link
Member

EJS: <%- and %>, e.g. <%- full_date(date, [format]) %>
SWIG: {{ and }}, e.g. {{ full_date(date, [format]) }}

@jackey8616
Copy link
Contributor Author

holy shooooooooot. i was deadly trying with {% %}.
that's {{ }} !!! what a surprise!

i will make full use of this function. 🤣 🤣 🤣
thx again.

@ivan-nginx
Copy link
Member

ivan-nginx commented Apr 11, 2018

Also, SWIG has similar syntax as Nunjuks.

For getting vars need to use {{ }} and for setting vars {% %}.
For example, u can use this things directly in templates:

{% set foo = "anything!" %}
{{ foo }}
// => anything!

jackey8616 added a commit to jackey8616/hexo-theme-next that referenced this pull request Apr 12, 2018
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
jackey8616 added a commit to jackey8616/hexo-theme-next that referenced this pull request Apr 12, 2018
    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
tongluyang pushed a commit to tongluyang/hexo-theme-next that referenced this pull request Nov 19, 2019
Add date_time_merge filed into 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.

2 participants