6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

Octopressで見出しタグを目次にする方法

Last updated at Posted at 2014-07-07

jekyll-toc-generatorというプラグインが使えますが、Octopressで使うと、ちょっとだけ不都合があったので、変更しました。

https://github.com/syui/jekyll-toc-generator

$ echo "gem 'nokogiri'" >> ~/octopress/Gemfile

$ cd ~/octopress

$ bundle install

$ cd ~/octopress/plugins/

$ curl -O https://raw.githubusercontent.com/syui/jekyll-toc-generator/master/_plugins/tocGenerator.rb

あとは、個別ページやメインページなど表示したい場所で{{ content }}{{ content | toc_generate }}に変更します。

source/_includes/article.html
- <div class="entry-content">{{ content }}</div>

+ <div class="entry-content">{{ content | toc_generate }}</div>

なお、有効無効の設定は、noToc: trueのオプションになります。デフォルトでは有効なので、無効にする設定です。

---
layout: post
noToc: true
---

これで、目次が自動形成されていい感じです。

参考:

Octopressで見出しの目次を作る方法 改 - 割り箸ポテチ

6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?