Split post date format code snippets.

Code improvement
This commit is contained in:
Cotes Chung 2020-07-23 22:23:31 +08:00
parent b2f0b4cb1b
commit aa23becd14
7 changed files with 37 additions and 23 deletions

View File

@ -6,4 +6,6 @@
tooltip: "%a, %b %e, %Y, %l:%M %p %z"
post: "%b %e, %Y"
post:
long: "%b %e, %Y"
short: "%b %e"

View File

@ -93,10 +93,7 @@
<div class="card">
<a href="{{ post.url | relative_url }}">
<div class="card-body">
<span class="timeago small">
{{ post.date | date: site.data.date_format.post }}
<i class="unloaded">{{ post.date | date_to_xmlschema }}</i>
</span>
{% include timeago.html date=post.date class="small" %}
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
<div class="text-muted small">
<p>

27
_includes/timeago.html Normal file
View File

@ -0,0 +1,27 @@
<!--
Date format snippet
v2.4.1
https://github.com/cotes2020/jekyll-theme-chirpy
© 2020 Cotes Chung
MIT License
-->
<span class="timeago {% if include.class %}{{ include.class }}{% endif %}"
{% if include.tooltip %}
data-toggle="tooltip"
data-placement="bottom"
title="{{ include.date | date: site.data.date_format.tooltip }}"
{% endif %}>
{% assign this_year = site.time | date: "%Y" %}
{% assign post_year = include.date | date: "%Y" %}
{% if post_year == this_year %}
{{ include.date | date: site.data.date_format.post.short }}
{% else %}
{{ include.date | date: site.data.date_format.post.long }}
{% endif %}
<i class="unloaded">{{ include.date | date_to_xmlschema }}</i>
</span>

View File

@ -18,7 +18,7 @@ layout: page
<li class="d-flex justify-content-between pl-md-3 pr-md-3">
<a href="{{ post.url | relative_url }}">{{ post.title }}</a>
<span class="dash flex-grow-1"></span>
<span class="text-muted small">{{ post.date | date: site.data.date_format.post }}</span>
<span class="text-muted small">{{ post.date | date: site.data.date_format.post.long }}</span>
</li>
{% endfor %}
</ul>

View File

@ -66,11 +66,8 @@ layout: page
<div class="post-meta text-muted">
<!-- posted date -->
<i class="far fa-clock fa-fw"></i>
<span class="timeago" data-toggle="tooltip" data-placement="bottom"
title="{{ post.date | date: site.data.date_format.tooltip }}">
{{ post.date | date: site.data.date_format.post }}
<i class="unloaded">{{ post.date | date_to_xmlschema }}</i>
</span>
{% include timeago.html date=post.date tooltip=true %}
<!-- page views -->
{% if site.google_analytics.pv.enabled %}
<i class="far fa-eye fa-fw"></i>

View File

@ -19,11 +19,7 @@ layout: default
<!-- Published date and author -->
<div>
Posted
<span class="timeago" data-toggle="tooltip" data-placement="bottom"
title="{{ page.date | date: site.data.date_format.tooltip }}">
{{ page.date | date: site.data.date_format.post }}
<i class="unloaded">{{ page.date | date_to_xmlschema }}</i>
</span>
{% include timeago.html date=page.date tooltip=true %}
by
<span class="author">
{% if page.author %}
@ -50,12 +46,7 @@ layout: default
{% if lastmod %}
<div>
Updated
<span class="timeago lastmod"
data-toggle="tooltip" data-placement="bottom"
title="{{ lastmod | date: site.data.date_format.tooltip }}">
{{ lastmod | date: site.data.date_format.post }}
<i class="unloaded">{{ lastmod | date_to_xmlschema}}</i>
</span>
{% include timeago.html date=lastmod class="lastmod" tooltip=true %}
</div>
{% endif %}

View File

@ -18,7 +18,7 @@ layout: page
<li class="d-flex justify-content-between pl-md-3 pr-md-3">
<a href="{{ post.url | relative_url }}">{{ post.title }}</a>
<span class="dash flex-grow-1"></span>
<span class="text-muted small">{{ post.date | date: site.data.date_format.post }}</span>
<span class="text-muted small">{{ post.date | date: site.data.date_format.post.long }}</span>
</li>
{% endfor %}
</ul>