Adding a tag cloud page to jekyll blog
2 mins readSeptember 06, 2020
blogging
hack
jekyll
javascript
Hmm… you have created a jekyll based blog and moved / added content to it? You notice there is no tags page in the default theme like in Blogger? Here is a simple solution to add them
- Add a tags frontmatter to all your posts
--- title: My first blogpost tags: hack java datastructures ... --- This is some content in your post. Lorem ipsum dolor ...
-
The above template will add tags (with hyperlink to a tag cloud page) in to your posts page.
-
Now, it’s time to create a tag page, which will have a list of all tags along with the posts who are tagged with these tags.
-
We will also use some javascript to add some interactivity to this page. (When user selects [a] tag[s], the associated posts will be shown below)
-
To supply these tags metadata to javascript, we will generate a JSON database in the same page using the liquid templating.
-
Create a page called tags.md in the root directory of the site and paste the content you find here
- To link posts to this tags page, add tags to your post page. We do this by editing the template for the posts page (so that we don’t need to add links in every post we do). Create a directory called
_layouts
in yoursite
directory and a file calledpost.md
in that with below content. This will serve as template for your posts page so feel free to customize it.--- layout: default --- <h1> {{ page.title }} </h1> <i>{{ page.date | date: '%B %d, %Y' }}</i> <br/> {% for tag in page.tags %} <code><a href="/acrhive?id={{tag}}">{{ tag }}</a></code> {% endfor %} <br/><br/><br/> {{ content }}
- We are done. For a demo, click on the above listed archive of this page.
Credits
Thanks to Ozzie Liu
for a nice blog on escaping the liquid processing in a jekyll page