Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Jekyll, how can I create a tag archive for pages?

Tags:

jekyll

I'm using tags on pages in Jekyll, like this:

---
title: Sample page
permalink: /sample/
tag: news
---

On my homepage, I have different sections that aggregate pages by tag, like this:

{% assign counter = '0' %}
{% for page in site.pages %}
{% for tag in page.tags %}
{% if tag == "news" and counter < '3' %}
{% capture counter %}{{ counter | plus:'1' }}{% endcapture %}
<li><a href="{{ page.permalink | prepend: site.baseurl }}">{{page.title}}</a></li>
<div class="summary">{{page.summary}}</div>
{% endif %}
{% endfor %}
{% endfor %}

This loop limits the news-tagged pages to 3, but I might have 10+ pages with the tag of "news." I want to include a "View all" tag at the bottom, so that users can see a complete list of all pages matching that tag.

I realize I could manually create a page and add similar code but without a limit to get all the pages. However, that's kind of tedious. I'd rather have Jekyll auto-generate a tag archive by default. I think Jekyll has a concept of generators, but I'm not sure how to implement a tag page generator.

How can I dynamically generate tag archive pages without creating and entering code on each page?

like image 380
Tom Johnson Avatar asked Oct 29 '25 17:10

Tom Johnson


2 Answers

check out jekyll-archives plugin. i just found out about this and am able to generate categories and tags pages. it does increase compile time coz of the number of categories and tags i have but it does what i need it to do. https://github.com/jekyll/jekyll-archives

like image 160
w1n78 Avatar answered Oct 31 '25 11:10

w1n78


Actually you do not need a plugin to do that. Check this out: http://codinfox.github.io/dev/2015/03/06/use-tags-and-categories-in-your-jekyll-based-github-pages/

like image 34
Codinfox Avatar answered Oct 31 '25 10:10

Codinfox



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!