jekyll でのタグの取り扱いについて

Published: 2019/2/24


このブログのタグページを作りたいだけなのだけれども、 やたら情報が錯綜していて苦労してしまったので、 備忘を兼ねて記録を残す。

一言で

jekyll-archives を使いましょう。

公式 Plugin ページ にも載っていて、ほぼほぼ安定していると思われます。

作業手順

Gemfile に以下を追加。

group :jekyll_plugins do
  gem 'jekyll-archives'
end

_config.yml に次を設定

plugins:
  - jekyll-archives
  # その他 plugins...

jekyll-archives:
  enabled: [tags]
  layouts:
    tag: tag
  permalinks:
    tag: '/tags/:name/'

_layout/tag.html に以下を作成

---
layout: default
title: {{ page.title }}
---

<h1>'{{ page.title }}' の一覧</h1>
{% for post in page.posts %}
  <!-- post を使って何かやる。 index.html と同じ感じ -->
{% endfor %}

これであとは各 post に、

---
tags: [tag1, tag2]
---

と記述することで、よろしくタグページが/tags/tag1 などに生成される。


Tags: jekyll

関連記事