Skip to content

Commit d56b71f

Browse files
committed
Split post date format code snippets.
Code improvement
1 parent 66b16a8 commit d56b71f

File tree

7 files changed

+37
-23
lines changed

7 files changed

+37
-23
lines changed

_data/date_format.yml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,6 @@
66

77

88
tooltip: "%a, %b %e, %Y, %l:%M %p %z"
9-
post: "%b %e, %Y"
9+
post:
10+
long: "%b %e, %Y"
11+
short: "%b %e"

_includes/related-posts.html

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,10 +93,7 @@ <h3 class="pt-2 mt-1 mb-4 ml-1" data-toc-skip>{{ site.data.label.post.relate_pos
9393
<div class="card">
9494
<a href="{{ post.url | relative_url }}">
9595
<div class="card-body">
96-
<span class="timeago small">
97-
{{ post.date | date: site.data.date_format.post }}
98-
<i class="unloaded">{{ post.date | date_to_xmlschema }}</i>
99-
</span>
96+
{% include timeago.html date=post.date class="small" %}
10097
<h3 class="pt-0 mt-1 mb-3" data-toc-skip>{{ post.title }}</h3>
10198
<div class="text-muted small">
10299
<p>

_includes/timeago.html

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
<!--
2+
Date format snippet
3+
4+
v2.4.1
5+
https://github.com/cotes2020/jekyll-theme-chirpy
6+
© 2020 Cotes Chung
7+
MIT License
8+
-->
9+
<span class="timeago {% if include.class %}{{ include.class }}{% endif %}"
10+
{% if include.tooltip %}
11+
data-toggle="tooltip"
12+
data-placement="bottom"
13+
title="{{ include.date | date: site.data.date_format.tooltip }}"
14+
{% endif %}>
15+
16+
{% assign this_year = site.time | date: "%Y" %}
17+
{% assign post_year = include.date | date: "%Y" %}
18+
19+
{% if post_year == this_year %}
20+
{{ include.date | date: site.data.date_format.post.short }}
21+
{% else %}
22+
{{ include.date | date: site.data.date_format.post.long }}
23+
{% endif %}
24+
25+
<i class="unloaded">{{ include.date | date_to_xmlschema }}</i>
26+
27+
</span>

_layouts/category.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1 class="pl-lg-2">
1818
<li class="d-flex justify-content-between pl-md-3 pr-md-3">
1919
<a href="{{ post.url | relative_url }}">{{ post.title }}</a>
2020
<span class="dash flex-grow-1"></span>
21-
<span class="text-muted small">{{ post.date | date: site.data.date_format.post }}</span>
21+
<span class="text-muted small">{{ post.date | date: site.data.date_format.post.long }}</span>
2222
</li>
2323
{% endfor %}
2424
</ul>

_layouts/home.html

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -66,11 +66,8 @@ <h1><a href="{{ post.url | relative_url }}">{{ post.title }}</a></h1>
6666
<div class="post-meta text-muted">
6767
<!-- posted date -->
6868
<i class="far fa-clock fa-fw"></i>
69-
<span class="timeago" data-toggle="tooltip" data-placement="bottom"
70-
title="{{ post.date | date: site.data.date_format.tooltip }}">
71-
{{ post.date | date: site.data.date_format.post }}
72-
<i class="unloaded">{{ post.date | date_to_xmlschema }}</i>
73-
</span>
69+
{% include timeago.html date=post.date tooltip=true %}
70+
7471
<!-- page views -->
7572
{% if site.google_analytics.pv.enabled %}
7673
<i class="far fa-eye fa-fw"></i>

_layouts/post.html

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,7 @@ <h1 data-toc-skip>{{ page.title }}</h1>
1919
<!-- Published date and author -->
2020
<div>
2121
Posted
22-
<span class="timeago" data-toggle="tooltip" data-placement="bottom"
23-
title="{{ page.date | date: site.data.date_format.tooltip }}">
24-
{{ page.date | date: site.data.date_format.post }}
25-
<i class="unloaded">{{ page.date | date_to_xmlschema }}</i>
26-
</span>
22+
{% include timeago.html date=page.date tooltip=true %}
2723
by
2824
<span class="author">
2925
{% if page.author %}
@@ -50,12 +46,7 @@ <h1 data-toc-skip>{{ page.title }}</h1>
5046
{% if lastmod %}
5147
<div>
5248
Updated
53-
<span class="timeago lastmod"
54-
data-toggle="tooltip" data-placement="bottom"
55-
title="{{ lastmod | date: site.data.date_format.tooltip }}">
56-
{{ lastmod | date: site.data.date_format.post }}
57-
<i class="unloaded">{{ lastmod | date_to_xmlschema}}</i>
58-
</span>
49+
{% include timeago.html date=lastmod class="lastmod" tooltip=true %}
5950
</div>
6051
{% endif %}
6152

_layouts/tag.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ <h1 class="pl-lg-2">
1818
<li class="d-flex justify-content-between pl-md-3 pr-md-3">
1919
<a href="{{ post.url | relative_url }}">{{ post.title }}</a>
2020
<span class="dash flex-grow-1"></span>
21-
<span class="text-muted small">{{ post.date | date: site.data.date_format.post }}</span>
21+
<span class="text-muted small">{{ post.date | date: site.data.date_format.post.long }}</span>
2222
</li>
2323
{% endfor %}
2424
</ul>

0 commit comments

Comments
 (0)