Wiki


Jekyll — Hacks

Archive

To generate the archive sorted by Years and Months without plugin

{%
  assign postsByYear = site.posts | group_by_exp:"post",
  "post.date | date: '%Y'"
%}
{% for year in postsByYear %}
  <h3>{{ year.name }}</h3>
  {%
    assign postsByMonth = year.items | group_by_exp:"post",
    "post.date | date: '%B'"
  %}
  {% for month in postsByMonth %}
    <h4>{{ month.name }}</h4>
    <ul>
      {% for post in month.items %}
      <li>
        <a href="{{ post.url }}">{{ post.title }}</a>
        <small>
          {{ post.date | date: "%B %-d, %Y"  }}
        </small>
      </li>
      {% endfor %}
    </ul>
  {% endfor %}
{% endfor %}

Tags

To generate list of posts sorted by tags without plugin

{% for tag in site.tags %}
  {% assign tag_name = tag | first %}
  {% assign tag_posts = tag | last %}
  <h3>{{ tag_name | capitalize | replace: "-", " " }}</h3>
  <small>{{ tag_posts | size}} Posts</small>
  <ul>
  {% for post in tag_posts %}
    {% if post.tags contains tag_name %}
      <li>
        <a href="{{ post.url }}">{{ post.title }}</a>
        <small>
          {{ post.date | date: "%B %-d, %Y"  }}
        </small>
      </li>
    {% endif %}
  {% endfor %}
  </ul>
{% endfor %}

Sitemap

To generate sitemap without plugin

---
layout: null
---
<?xml version="1.0" encoding="UTF-8"?>
<urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9">

  {% for post in site.posts %}{% unless post.published == false %}<url>
    <loc>{{ site.url }}{{ post.url }}</loc>
    {% if post.date %}<lastmod>{{ post.date | date_to_xmlschema }}</lastmod>{% endif %}
  </url>{% endunless %}
  {% endfor %}
  {% for page in site.pages %}<url>
    <loc>{{ site.url }}{{ page.url | remove: "index.html" }}</loc>
    {% if page.date %}<lastmod>{{ page.date | date_to_xmlschema }}</lastmod>{% else %}<lastmod>{{ site.time | date_to_xmlschema }}</lastmod>{% endif %}
  </url>
    {% endfor %}
</urlset>

See Also