Skip to content

Instantly share code, notes, and snippets.

@DavidGoussev
Last active March 21, 2016 03:59
Show Gist options
  • Select an option

  • Save DavidGoussev/2caf5f6ce3d5ac4922c8 to your computer and use it in GitHub Desktop.

Select an option

Save DavidGoussev/2caf5f6ce3d5ac4922c8 to your computer and use it in GitHub Desktop.
adding tags to jekyll blog
<ul class="tags">
{% for tag in page.tags %}
<li><a href="{{site.baseurl}}tags#{{tag}}" class="tag">{{ tag }}</a></li>
{% endfor %}
</ul>
---
layout: page
title: tags
---
{% capture site_tags %}{% for tag in site.tags %}{{ tag | first }}{% unless forloop.last %},{% endunless %}{% endfor %}{% endcapture %}
{% assign tag_words = site_tags | split:',' | sort %}
<div id="tags">
<h5> Tags in Blog</h5>
<ul class="tags">
<!-- cycles through tag list and creates header row of all tags used in site with accompanying per-tag counts...-->
{% for item in (0..site.tags.size) %}{% unless forloop.last %}
{% capture this_word %}{{ tag_words[item] | strip_newlines }}{% endcapture %}
<li ><a href="#{{ this_word | cgi_escape }}" class="tag">{{ this_word }} <span>({{ site.tags[this_word].size }})</span></a></li>
{% endunless %}{% endfor %}
</ul>
<!--cycles through tag list and creates subheader for each tag name...-->
{% for item in (0..site.tags.size) %}{% unless forloop.last %}
{% capture this_word %}{{ tag_words[item] | strip_newlines }}{% endcapture %}
<h2 id="{{ this_word | cgi_escape }}">{{ this_word }}</h2>
<!-- lists all posts corresponding to specific tag...-->
{% for post in site.tags[this_word] %}{% if post.title != null %}
<div>
<span><a href="{{ post.url }}">{{ post.title }}</a></span>
<small><span>{{ post.date | date_to_string }}</span></small>
</div>
{% endif %}{% endfor %}
{% endunless %}{% endfor %}
</div>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment