Giter VIP home page Giter VIP logo

eleventy-plugin-toc's Introduction

eleventy-plugin-toc

This Eleventy plugin will generate a TOC from page content using an Eleventy filter.

Default Options

{
  tags: ['h2', 'h3', 'h4'], // which heading tags are selected
                            // headings must each have an ID attribute
  wrapper: 'nav',           // element to put around the root `ol`
  wrapperClass: 'toc'       // class for the element around the root `ol`
}

Usage

1. Install the plugin

npm i --save eleventy-plugin-toc

2. Add the plugin to Eleventy config

Note: you'll need to make sure you have ids on heading elements before this plugin will create a TOC. If there aren't ids, there will be nothing for links in this TOC to link to. (I recommend using markdown-it-anchor to add those ids to the headings: Eleventy config example)

// .eleventy.js

const pluginTOC = require('eleventy-plugin-toc')

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(pluginTOC)
}

3. Use the filter in your template

<article>
  {{ content }}
</article>
<aside>
  {{ content | toc }}
</article>

4. Override default options if necessary

Pass a stringified JSON object (must be JSON.parse()-able) as an option for in your template. Because this is an object, you only need to include the key-value pairs you need to override; defaults will be preserved.

<aside>
  {{ content | toc: '{"tags":["h2","h3"],"wrapper":"div","wrapperClass":"content-tableau"}' }}
</article>

Roadmap

  • I'd like to expose the default options to overriding in an Eleventy config file
  • Some tests would be nice

eleventy-plugin-toc's People

Contributors

jdsteinbach avatar

Stargazers

Abdul Najeeb Anwari avatar

Watchers

James Cloos avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.