Easy way to maintain tags on jekyll's blog

I use the standard jekyll installation for blogging, everything is going well. In addition, I would really like to tag my posts.

I can mark a message using the front YAML task, but how do I create pages for each tag that can display all the messages for the tag?

+42
ruby tags tagging jekyll liquid
Sep 11 '09 at 3:25
source share
6 answers

This method will generate a page for each category: https://gist.github.com/524748

It uses the Jekyll Generator plugin, as well as a subclass of Page.

+14
Dec 14 '10 at 19:51
source share

Here is a solution with alphabetically sorted tags on one page .
It uses only Liquid, which means it works on GitHub pages:

{% capture tags %} {% for tag in site.tags %} {{ tag[0] }} {% endfor %} {% endcapture %} {% assign sortedtags = tags | split:' ' | sort %} {% for tag in sortedtags %} <h3 id="{{ tag }}">{{ tag }}</h3> <ul> {% for post in site.tags[tag] %} <li><a href="{{ post.url }}">{{ post.title }}</a></li> {% endfor %} </ul> {% endfor %} 

You can see it in action here .




EDIT:

It is also possible to generate a separate page for each tag without plugins (which will work on GitHub pages).

I have a more detailed explanation on my blog:
Separate pages for each tag / category using Jekyll (without plugins)

First you need a new layout file:

/_layouts/tagpage.html :

 --- layout: default --- <h1>{{ page.tag }}</h1> <ul> {% for post in site.tags[page.tag] %} <li> {{ post.date | date: "%B %d, %Y" }}: <a href="{{ post.url }}">{{ post.title }}</a> </li> {% endfor %} </ul> 

Using this layout file, you can add a new tag page by adding a new file with two lines of the front YAML array.

Here is an example jekyll tag:

/tags/jekyll/index.html :

 --- layout: tagpage tag: jekyll --- 

The only drawback of this approach is that every time you use a new tag for the first time, you should remember to create a new two-line file for it.

To generate a root index file (i.e. a tag list that links to /tags/jekyll/index.html , etc.), you can use a similar solution similar to the one written on top of this answer, where I generate one page with alpha-sorted tags:

 {% capture tags %} {% for tag in site.tags %} {{ tag[0] }} {% endfor %} {% endcapture %} {% assign sortedtags = tags | split:' ' | sort %} {% for tag in sortedtags %} <a href="/tags/{{ tag }}/">{{ tag }}</a><br> {% endfor %} 

This will result in a list of such links:

 <ul> <li><a href="/tags/.net/">.net</a></li> <li><a href="/tags/authentication/">authentication</a></li> <li><a href="/tags/backup/">backup</a></li> </ul> 

Please note that this solution uses a space for tagging, so it doesn’t work when your tags contain spaces and Evgeny Brikman’s comment also applies here.

+73
Jan 08 '14 at 17:29
source share

Check out sites using jekyll . There are several custom forks that have implemented tag functions, hopefully also in the way you want :-)

+8
Sep 15 '09 at 14:18
source share

I had the same question and stumbled upon this: http://gist.github.com/143571 .

This is a grabbed task that generates a list of tags. I changed it a bit and my version is: http://github.com/mattfoster/mattfoster.github.com/blob/master/Rakefile .

Until this gives you a page per tag, you can use anchors that are halfway!

+5
Feb 25 '10 at 18:53
source share

I use the large Jekyll Tagging plugin that automatically generates a tag cloud and tags. Easy to install and use.

Here is the page for the photo tag on my blog (in French), and you can see the tag cloud below.

+1
Apr 30 '15 at 10:12
source share

Based on the Christian answer above, I made a bash script that does what it described.

https://github.com/ObjectiveTruth/objectivetruth.imtqy.com/blob/master/rebuild_tags.sh

In the /non_website_resources/ directory, make sure that the line /non_website_resources/ contains the following vim script line.

AND

Make the /_layouts/tagpage.html shown in the Christian answer above, but rename it to /_layouts/tag_pages.html

The file structure should be like this:

 .jekyll_website_root β”œβ”€β”€ _posts β”œβ”€β”€ _layout β”‚ β”œβ”€β”€ tag_pages.html β”œβ”€β”€ rebuild_tags.sh 

Running from the root directory ./rebuild_tags.sh

If you are denied permission, be sure to run chmod 777 rebuild_tags.sh




If you look at the comments on the scripts, this is pretty simple:

  • Uses sed to find all tags in each .md file in the _post directory

  • Uses sed to process data in proper format

  • Accepts all unique tags and creates a directory and index.html for each

This way, if you have new tags, just run the script to rebuild the pages before clicking on github

Nice easy way to tag without plugins




EDIT

Removed dependency on other files. Just need one script!

+1
Jul 08 '15 at 6:38
source share



All Articles