Skip to content

Commit 5037395

Browse files
lehnerpatnielsenramon
authored andcommitted
Extract common article info footer into an include
The article info footer (article date, "x minute read", and tags) occur in three places (article list, article view, and articles-by-tag). This commit deduplicates the redundant code from these three places into a single include.
1 parent 9a05590 commit 5037395

File tree

4 files changed

+24
-58
lines changed

4 files changed

+24
-58
lines changed

_includes/article/info-footer.html

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<div class="article-list-footer">
2+
<span class="article-list-date">
3+
{{ include.post.date | date: "%B %-d, %Y" }}
4+
</span>
5+
<span class="article-list-divider">-</span>
6+
<span class="article-list-minutes">
7+
{% capture words %}
8+
{{ include.post.content | number_of_words }}
9+
{% endcapture %}
10+
{% unless words contains "-" %}
11+
{{ words | plus: 250 | divided_by: 250 | append: " minute read" }}
12+
{% endunless %}
13+
</span>
14+
<span class="article-list-divider">-</span>
15+
<div class="article-list-tags">
16+
{% for tag in include.post.tags %}
17+
{% assign tag_name = site.my_tags | where: "slug", tag | map: "name" | first %}
18+
<a href="{{ 'tag/' | relative_url }}{{ tag }}" title="See all posts with tag '{{ tag_name }}'">{{ tag_name }}</a>
19+
{% endfor %}
20+
</div>
21+
</div>

_layouts/articles_by_tag.html

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -16,24 +16,7 @@ <h5>{{ post.title }}</h5>
1616
{{ post.excerpt }}
1717
{% endif %}
1818
</p>
19-
<div class="article-list-footer">
20-
<span class="article-list-date">
21-
{{ post.date | date: "%B %-d, %Y" }}
22-
</span>
23-
<span class="article-list-divider">-</span>
24-
<span class="article-list-minutes">
25-
{% capture words %}
26-
{{ post.content | number_of_words }}
27-
{% endcapture %}
28-
{% unless words contains "-" %}
29-
{{ words | plus: 250 | divided_by: 250 | append: " minute read" }}
30-
{% endunless %}
31-
</span>
32-
<span class="article-list-divider">-</span>
33-
{% for tag in post.tags %}
34-
<a href="{{ 'tag/' | relative_url }}{{ tag }}" title="See all posts by this tag">{{ tag }}</a>
35-
{% endfor %}
36-
</div>
19+
{% include article/info-footer.html post=post %}
3720
</li>
3821
{% endfor %}
3922
</ul>

_layouts/post.html

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -10,26 +10,7 @@
1010
<header class="article-header">
1111
<h1>{{ page.title }}</h1>
1212
<p>{{ page.description }}</p>
13-
<div class="article-list-footer">
14-
<span class="article-list-date">
15-
{{ page.date | date: "%B %-d, %Y" }}
16-
</span>
17-
<span class="article-list-divider">-</span>
18-
<span class="article-list-minutes">
19-
{% capture words %}
20-
{{ page.content | number_of_words }}
21-
{% endcapture %}
22-
{% unless words contains "-" %}
23-
{{ words | plus: 250 | divided_by: 250 | append: " minute read" }}
24-
{% endunless %}
25-
</span>
26-
<span class="article-list-divider">-</span>
27-
<div class="article-list-tags">
28-
{% for tag in page.tags %}
29-
<a href="{{ 'tag/' | relative_url }}{{ tag }}">{{ tag }}</a>
30-
{% endfor %}
31-
</div>
32-
</div>
13+
{% include article/info-footer.html post=page %}
3314
</header>
3415

3516
<div class="article-content">

index.html

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,7 @@ <h5>
2020
{{ post.excerpt }}
2121
{% endif %}
2222
</p>
23-
<div class="article-list-footer">
24-
<span class="article-list-date">
25-
{{ post.date | date: "%B %-d, %Y" }}
26-
</span>
27-
<span class="article-list-divider">-</span>
28-
<span class="article-list-minutes">
29-
{% capture words %}
30-
{{ post.content | number_of_words }}
31-
{% endcapture %}
32-
{% unless words contains "-" %}
33-
{{ words | plus: 250 | divided_by: 250 | append: " minute read" }}
34-
{% endunless %}
35-
</span>
36-
<span class="article-list-divider">-</span>
37-
<div class="article-list-tags">
38-
{% for tag in post.tags %}
39-
<a href="{{ 'tag/' | relative_url }}{{ tag }}">{{ tag }}</a>
40-
{% endfor %}
41-
</div>
42-
</div>
23+
{% include article/info-footer.html post=post %}
4324
</li>
4425
{% endfor %}
4526
{% if paginator.total_pages > 1 %}

0 commit comments

Comments
 (0)