Skip to content

Commit

Permalink
Extract common article info footer into an include
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lehnerpat authored and nielsenramon committed Sep 18, 2019
1 parent 9a05590 commit 5037395
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 58 deletions.
21 changes: 21 additions & 0 deletions _includes/article/info-footer.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<div class="article-list-footer">
<span class="article-list-date">
{{ include.post.date | date: "%B %-d, %Y" }}
</span>
<span class="article-list-divider">-</span>
<span class="article-list-minutes">
{% capture words %}
{{ include.post.content | number_of_words }}
{% endcapture %}
{% unless words contains "-" %}
{{ words | plus: 250 | divided_by: 250 | append: " minute read" }}
{% endunless %}
</span>
<span class="article-list-divider">-</span>
<div class="article-list-tags">
{% for tag in include.post.tags %}
{% assign tag_name = site.my_tags | where: "slug", tag | map: "name" | first %}
<a href="{{ 'tag/' | relative_url }}{{ tag }}" title="See all posts with tag '{{ tag_name }}'">{{ tag_name }}</a>
{% endfor %}
</div>
</div>
19 changes: 1 addition & 18 deletions _layouts/articles_by_tag.html
Original file line number Diff line number Diff line change
Expand Up @@ -16,24 +16,7 @@ <h5>{{ post.title }}</h5>
{{ post.excerpt }}
{% endif %}
</p>
<div class="article-list-footer">
<span class="article-list-date">
{{ post.date | date: "%B %-d, %Y" }}
</span>
<span class="article-list-divider">-</span>
<span class="article-list-minutes">
{% capture words %}
{{ post.content | number_of_words }}
{% endcapture %}
{% unless words contains "-" %}
{{ words | plus: 250 | divided_by: 250 | append: " minute read" }}
{% endunless %}
</span>
<span class="article-list-divider">-</span>
{% for tag in post.tags %}
<a href="{{ 'tag/' | relative_url }}{{ tag }}" title="See all posts by this tag">{{ tag }}</a>
{% endfor %}
</div>
{% include article/info-footer.html post=post %}
</li>
{% endfor %}
</ul>
Expand Down
21 changes: 1 addition & 20 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,26 +10,7 @@
<header class="article-header">
<h1>{{ page.title }}</h1>
<p>{{ page.description }}</p>
<div class="article-list-footer">
<span class="article-list-date">
{{ page.date | date: "%B %-d, %Y" }}
</span>
<span class="article-list-divider">-</span>
<span class="article-list-minutes">
{% capture words %}
{{ page.content | number_of_words }}
{% endcapture %}
{% unless words contains "-" %}
{{ words | plus: 250 | divided_by: 250 | append: " minute read" }}
{% endunless %}
</span>
<span class="article-list-divider">-</span>
<div class="article-list-tags">
{% for tag in page.tags %}
<a href="{{ 'tag/' | relative_url }}{{ tag }}">{{ tag }}</a>
{% endfor %}
</div>
</div>
{% include article/info-footer.html post=page %}
</header>

<div class="article-content">
Expand Down
21 changes: 1 addition & 20 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -20,26 +20,7 @@ <h5>
{{ post.excerpt }}
{% endif %}
</p>
<div class="article-list-footer">
<span class="article-list-date">
{{ post.date | date: "%B %-d, %Y" }}
</span>
<span class="article-list-divider">-</span>
<span class="article-list-minutes">
{% capture words %}
{{ post.content | number_of_words }}
{% endcapture %}
{% unless words contains "-" %}
{{ words | plus: 250 | divided_by: 250 | append: " minute read" }}
{% endunless %}
</span>
<span class="article-list-divider">-</span>
<div class="article-list-tags">
{% for tag in post.tags %}
<a href="{{ 'tag/' | relative_url }}{{ tag }}">{{ tag }}</a>
{% endfor %}
</div>
</div>
{% include article/info-footer.html post=post %}
</li>
{% endfor %}
{% if paginator.total_pages > 1 %}
Expand Down

0 comments on commit 5037395

Please sign in to comment.