田舎エンジニアの備忘録

Back

astro-paperに標準で入っている目次関係のプラグインを設定した。 目次の実現方法はいろいろあるが、とりあえず標準機能でできることをやってみた。

初期設定#

初期状態は以下。
astro.config.mjs

目次 remark-toc#

キーワードにマッチした最初のヘッディングに目次が生成される。
デフォルトキーワードは以下。case-insensitive

 heading (string, default: '(table[ -]of[ -])?contents?|toc')
  — heading to look for, wrapped in new RegExp('^(' + value + ')$', 'i')
javascript

折りたたみ remark-collapse#

ヘッディングが”Table of contents”の場合、その章が折りたたまれる。

変更後の設定#

設定内容は

  • ヘッディングが Contents|目次|記事の目次 のとき目次を作成
  • Contents|記事の目次 のとき折りたたみ
  • 目次領域が記事と区別がつくように見た目を変更

目次、折りたたみ#

astro.config.mjs

見た目#

styles/base.css

参考#

Astroで目次を設定
https://www.infolab.blue/blog/astro-update-toc-settings
Author Takeshi
Published at March 8, 2024