03 October 2017

I often have little techie things I want to share that don’t merit full posts.

I like Brandur’s Fragments section and Thoughtbot’s TIL (Today I Learned) and have wanted to add this capability to my blog for a while.

I’ve been doing some cleanup in my blog and came across Jekyll Collection.

Not everything is a post or a page.
Collections allow you to define a new type of document that behave like Pages or Posts do normally, but also have their own unique properties and namespace.

So, I did the work to add a Fragments section.

In _config.yml I configured a collection fragments which specified that every file in the _fragments directory would be copied over.

    output: true

This makes available a site.fragments variable.

By default, the permalink for any posts in there will be in /fragments, which is what I want.

I created a fragments.md page for listing the fragments as something like:

<section class="content">
  <ul class="listing">
    {% for item in site.fragments %}
      {% if item.title != null %}
          <a href="{{ item.url }}">{{ item.title }}</a>
      {% endif %}
    {% endfor %}

blog comments powered by Disqus