Add page taxonomy links for tags and categories

- Customizable text via _data file
- Enable/disable links by setting archive page filenames in _config.yml
This commit is contained in:
Michael Rose 2016-03-10 21:53:28 -05:00
parent f63b8fe294
commit 4427cf4c8e
10 changed files with 56 additions and 29 deletions

View file

@ -177,6 +177,10 @@ paginate: 5 # amount of posts to show
paginate_path: /page:num/ paginate_path: /page:num/
timezone: America/New_York # http://en.wikipedia.org/wiki/List_of_tz_database_time_zones timezone: America/New_York # http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
# Archive Page Filenames (example: <base_path>/archive-filename/ ~> "archive-filename")
tags_archive_filename : "tag-archive"
categories_archive_filename : "category-archive"
# HTML Compression # HTML Compression
# http://jch.penibelst.de/ # http://jch.penibelst.de/
compress_html: compress_html:

View file

@ -3,16 +3,18 @@
# English (default) # English (default)
# ----------------- # -----------------
en: &DEFAULT_EN en: &DEFAULT_EN
pagination_previous: "Previous" pagination_previous : "Previous"
pagination_next: "Next" pagination_next : "Next"
toc_label: "Overview" toc_label : "Overview"
ext_link_label: "Direct Link" ext_link_label : "Direct Link"
share_on: "Share on" share_on_label : "Share on"
date_label: "Last Updated:" date_label : "Last Updated:"
related_label: "You May Also Enjoy" tags_label : "Tags:"
follow_label: "Follow:" categories_label : "Categories:"
feed_label: "Feed" related_label : "You May Also Enjoy"
powered_by: "Powered by" follow_label : "Follow:"
feed_label : "Feed"
powered_by : "Powered by"
en_US: en_US:
<<: *DEFAULT_EN <<: *DEFAULT_EN
en_UK: en_UK:

View file

@ -1,15 +1,34 @@
{% include base_path %}
{% comment %} {% comment %}
<!-- Sort page.tags alphabetically regardless of case e.g. a B c d E --> <!-- Sort page.tags alphabetically regardless of case e.g. a B c d E -->
<!-- modified from http://www.codeofclimber.ru/2015/sorting-site-tags-in-jekyll/ --> <!-- modified from http://www.codeofclimber.ru/2015/sorting-site-tags-in-jekyll/ -->
{% endcomment %} {% endcomment %}
{% capture page_tags %}{% for tag in page.tags %}{{ tag | downcase }}#{{ tag }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %} {% if site.tags_archive_filename %}
{% assign tag_hashes = (page_tags | split: ',' | sort:0) %} {% capture page_tags %}{% for tag in page.tags %}{{ tag | downcase }}#{{ tag }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
{% assign tag_hashes = (page_tags | split: ',' | sort:0) %}
Filed under: <span class="post__taxonomy-wrapper" itemprop="keywords"> <p><strong>{{ site.data.ui-text[site.locale].tags_label }}</strong> <span class="page__taxonomy-wrapper" itemprop="keywords">
{% for hash in tag_hashes %} {% for hash in tag_hashes %}
{% assign keyValue = hash | split: '#' %} {% assign keyValue = hash | split: '#' %}
{% capture tag_word %}{{ keyValue[1] | strip_newlines }}{% endcapture %} {% capture tag_word %}{{ keyValue[1] | strip_newlines }}{% endcapture %}
{% if forloop.last %} and{% endif %} <a href="{{ site.url }}{{ tag_word | slugify | prepend: '/tag/' | append: '/' }}" class="post__taxonomy-item" rel="tag">{{ tag_word }}</a>{% unless forloop.last %}, {% endunless %} <a href="{{ base_path }}{{ tag_word | slugify | prepend: '/#' | prepend: site.tags_archive_filename | prepend: "/" }}" class="page__taxonomy-item" rel="tag">{{ tag_word }}</a>{% unless forloop.last %}, {% endunless %}
{% endfor %} {% endfor %}
</span> </span>
</p>
{% endif %}
{% if site.categories_archive_filename %}
{% capture page_categories %}{% for category in page.categories %}{{ category | downcase }}#{{ category }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
{% assign category_hashes = (page_categories | split: ',' | sort:0) %}
<p><strong>{{ site.data.ui-text[site.locale].categories_label }}</strong> <span class="page__taxonomy-wrapper" itemprop="keywords">
{% for hash in category_hashes %}
{% assign keyValue = hash | split: '#' %}
{% capture category_word %}{{ keyValue[1] | strip_newlines }}{% endcapture %}
<a href="{{ base_path }}{{ category_word | slugify | prepend: '/#' | prepend: site.categories_archive_filename | prepend: "/" }}" class="page__taxonomy-item" rel="tag">{{ category_word }}</a>{% unless forloop.last %}, {% endunless %}
{% endfor %}
</span>
</p>
{% endif %}

View file

@ -19,12 +19,14 @@ layout: default
{% if page.link %}<div><a href="{{ page.link }}" class="btn">{{ site.data.ui-text[site.locale].ext_link_label }}</a></div>{% endif %} {% if page.link %}<div><a href="{{ page.link }}" class="btn">{{ site.data.ui-text[site.locale].ext_link_label }}</a></div>{% endif %}
</section> </section>
<footer> {% if site.share and page.share %}{% include social-share.html %}{% endif %}
{% if site.share and page.share %}{% include social-share.html %}{% endif %}
<footer class="page__meta">
{% include page__taxonomy.html %}
{% if page.modified %} {% if page.modified %}
<p class="byline"><strong>{{ site.data.ui-text[site.locale].date_label }}</strong> <time datetime="{{ page.modified | date: "%Y-%m-%d" }}">{{ page.modified | date: "%B %d, %Y" }}</time></p> <p class="page__date"><strong>{{ site.data.ui-text[site.locale].date_label }}</strong> <time datetime="{{ page.modified | date: "%Y-%m-%d" }}">{{ page.modified | date: "%B %d, %Y" }}</time></p>
{% elsif page.date %} {% elsif page.date %}
<p class="byline"><strong>{{ site.data.ui-text[site.locale].date_label }}</strong> <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: "%B %d, %Y" }}</time></p> <p class="page__date"><strong>{{ site.data.ui-text[site.locale].date_label }}</strong> <time datetime="{{ page.date | date_to_xmlschema }}">{{ page.date | date: "%B %d, %Y" }}</time></p>
{% endif %} {% endif %}
</footer> </footer>
</div><!-- /.article-wrap --> </div><!-- /.article-wrap -->

View file

@ -10,7 +10,7 @@ author_profile: false
{% for category in group_names %} {% for category in group_names %}
{% assign posts = group_items[forloop.index0] %} {% assign posts = group_items[forloop.index0] %}
<h2 class="archive__subtitle">{{ category }}</h2> <h2 id="{{ category | slugify }}" class="archive__subtitle">{{ category }}</h2>
{% for post in posts %} {% for post in posts %}
{% include archive-list-single.html %} {% include archive-list-single.html %}
{% endfor %} {% endfor %}

View file

@ -12,7 +12,7 @@ author_profile: false
{% unless collection.output == false or collection.label == 'posts' %} {% unless collection.output == false or collection.label == 'posts' %}
{% capture label %}{{ collection.label }}{% endcapture %} {% capture label %}{{ collection.label }}{% endcapture %}
{% if label != written_label %} {% if label != written_label %}
<h2 class="archive__subtitle">{{ label }}</h2> <h2 id="{{ label | slugify }}" class="archive__subtitle">{{ label }}</h2>
{% capture written_label %}{{ label }}{% endcapture %} {% capture written_label %}{{ label }}{% endcapture %}
{% endif %} {% endif %}
{% endunless %} {% endunless %}

View file

@ -9,7 +9,7 @@ permalink: /portfolio/
{% for category in group_names %} {% for category in group_names %}
{% assign posts = group_items[forloop.index0] %} {% assign posts = group_items[forloop.index0] %}
<h2 class="archive__subtitle">{{ category }}</h2> <h2 id="{{ category | slugify }}" class="archive__subtitle">{{ category }}</h2>
{% for post in posts %} {% for post in posts %}
{% include archive-list-single.html %} {% include archive-list-single.html %}
{% endfor %} {% endfor %}

View file

@ -10,7 +10,7 @@ author_profile: false
{% for category in group_names %} {% for category in group_names %}
{% assign posts = group_items[forloop.index0] %} {% assign posts = group_items[forloop.index0] %}
<h2 class="archive__subtitle">{{ category }}</h2> <h2 id="{{ category | slugify }}" class="archive__subtitle">{{ category }}</h2>
{% for post in posts %} {% for post in posts %}
{% include archive-list-single.html %} {% include archive-list-single.html %}
{% endfor %} {% endfor %}

View file

@ -10,7 +10,7 @@ author_profile: false
{% for tag in group_names %} {% for tag in group_names %}
{% assign posts = group_items[forloop.index0] %} {% assign posts = group_items[forloop.index0] %}
<h2 class="archive__subtitle">{{ tag }}</h2> <h2 id="{{ tag | slugify }}" class="archive__subtitle">{{ tag }}</h2>
{% for post in posts %} {% for post in posts %}
{% include archive-list-single.html %} {% include archive-list-single.html %}
{% endfor %} {% endfor %}

View file

@ -10,7 +10,7 @@ author_profile: false
{% for post in site.posts %} {% for post in site.posts %}
{% capture year %}{{ post.date | date: '%Y' }}{% endcapture %} {% capture year %}{{ post.date | date: '%Y' }}{% endcapture %}
{% if year != written_year %} {% if year != written_year %}
<h2 class="archive__subtitle">{{ year }}</h2> <h2 id="{{ year | slugify }}" class="archive__subtitle">{{ year }}</h2>
{% capture written_year %}{{ year }}{% endcapture %} {% capture written_year %}{{ year }}{% endcapture %}
{% endif %} {% endif %}
{% include archive-list-single.html %} {% include archive-list-single.html %}