Stock photo of a laptop, coffee, pen, notepad and phone

Photo by Andrew Neel from Unsplash

I started writing this blog in the spirit of Visa’s do 100’s things. The best way to become a better writer is to write. Writing and writing energy is not scarce. It’s not like you have a finite number of things you can write in your life. The more you write, the more you can write. If you write an article about an idea, it doesn’t need to be perfect. You can always write more about it later.

I started writing on Ghost because it was easy to set up and maintain. At first, I didn’t mention my name anywhere. Eventually, I decided to merge it with my personal site after I became more confident with my writing and so that I could gain more control over how the site looked. As an engineer, I love being able to take advantage of Git for version control, setting up my writing environment using VS Code and knowing that I can easily maintain and migrate it from Jekyll if necessary.

Jekyll by default puts all blog posts into one feed, but sometimes, I want to write something small, a snippet, a note mostly for myself, that doesn’t really fit in Bits, Bips and Bricks.

By taking advantage of Jekyll categories and tags you can easily have multiple sub blogs each with their own Atom feed using only Liquid.

A category can be defined using the front matter keys category or categories (a space separated list of categories) or putting a directory above the post’s _post directory with the name of the category.

A tag can be defined using can be defined using the front matter keys tag or tags (a space separated list of tags)

This snippet is built to match the style of Minma, but similar logic can be used for other themes.

Copy the following code and paste it in _includes/blog.html:

<div class="blog">
    <h2 class="post-list-heading">{{ page.list_title | default: "Posts" }}</h2>
    <ul class="post-list">
      {%- for post in site.posts -%}
      {%- if post.categories contains include.category or post.tags contains include.tag -%}
      <li>
        {%- assign date_format = site.minima.date_format | default: "%b %-d, %Y" -%}
        <span class="post-meta">{{ post.date | date: date_format }}</span>
        <h3>
          <a class="post-link" href="{{ post.url | relative_url }}">
            {{ post.title | escape }}
          </a>
        </h3>
        {%- if site.show_excerpts -%}
          {{ post.excerpt }}
        {%- endif -%}
      </li>
      {%-endif -%}
      {%- endfor -%}

    </ul>

    {%- if include.category and site.feed.categories contains include.category -%}
      {% unless include.tag %}
      {% assign feed_location = site.feed.categories[include.category].path | default: '/feed/' | append: include.category | append: '.xml' | relative_url %}
        <p class="rss-subscribe">subscribe <a href="{{ '/feed/' | append: include.category | append: '.xml' | relative_url }}">via RSS</a></p>
        {% endunless %}
    {%- endif -%}

    {%- if include.tag and site.feed.tags contains include.tag -%}
    {% unless include.category %}
      <p class="rss-subscribe">subscribe <a href="{{ '/feed/' | append: include.tag | append: '.xml' | relative_url }}">via RSS</a></p>
    {% endunless %}
    {%- endif -%}

</div>

The above code is available under the MIT license and contains code from minima/_layouts/home.html

On the page that you want a sub blog with only posts from a certain category:

{% include blog.html category="category_name" %}

On the page that you want a sub blog with only posts with a certain tag:

{% include blog.html tag="tag_name" %}

If you don’t add a category or tag parameter, then all posts will be in the sub blog.

Minima assumes that if there are no posts, the feed will not be shown. I disagree, you can have a blog without blog posts.

Make sure to update your _config.yml according to the instructions for jekyll-feed to make sure that the feeds for your category or tag are generated.