Now there is an official plugin available for this. jekyll-archives
.
In order to make use of it,
Add jekyll-archives
to your Gemfile
and _config.yml
file.
add a configuration something similar to the below as per your need.
jekyll-archives:
enabled: all
layouts:
year: archive/year
month: archive/month
day: archive/day
tag: archive/tag
category: archive/category
permalinks:
year: '/:year/'
month: '/:year/:month/'
day: '/:year/:month/:day/'
tag: '/tags/:name/'
category: '/category/:name/'
The layouts
can make use of the following page attributes depending on the archive type
.
- page.type - (Any one fo the following.
year
, month
, day
, tag
, category
)
- page.title - (Only available for the type tag and category.
Nil
otherwise.)
- page.date - (Depending on
page.type
you should parse out the date and month field )
- page.posts - (List of posts for this archive)
Here is a sample layout for archive based on years
<h1>Archive of posts from {{ page.date | date: "%Y" }}</h1>
<ul class="posts">
{% for post in page.posts %}
<li>
<span class="post-date">{{ post.date | date: "%b %-d, %Y" }}</span>
<a class="post-link" href="{{ post.url | prepend: site.baseurl }}">{{ post.title }}</a>
</li>
{% endfor %}
</ul>