GithubHelp home page GithubHelp logo

anatoo / metalsmith-autotoc Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 9.0 93 KB

[UNMAINTAINED] A metalsmith plugin for generating table of contents.

JavaScript 100.00%
metalsmith-plugin metalsmith deprecated

metalsmith-autotoc's Introduction


๐Ÿ“Œ Deprecation Notice

This repository is deprecated and no more work will be done on this. Please use metalsmith/table-of-contents.


metalsmith-autotoc

A metalsmith plugin to generate table of contents of a document.

This plugin generate table of contents object to document's metadata.

Installation

$ npm install metalsmith-autotoc

Configuration

headerIdPrefix

Default: ``

This value will be added to generated header ids as a prefix.

selector

Default: 'h2,h3,h4,h5,h6'

A list of header selectors to search.

Example

Source file src/index.html:

---
autotoc: true
template: 'layout.eco'
---
<h2>aaa</h2>
<p>paragraph</p>

<h3>bbb</h3>
<p>paragraph</p>

<h3>ccc</h3>
<p>paragraph</p>

<h2>ddd</h2>
<p>paragraph</p>

Template file templates/layout.eco:

<% renderToc = (items) => %>
<ol class="toc">
  <% for item in items: %>
  <li><a href="#<%= item.id %>"><%= item.text %></a>
    <% if item.children.length > 0: %><%- renderToc(item.children) %><% end %>
  </li>
  <% end %>
</ol>
<% end %>

<% if @toc: %>
<%- renderToc(@toc) %>
<% end %>

<%- @contents %>

Build file build.js:

var metalsmith = require('metalsmith');
var autotoc = require('metalsmith-autotoc');
var templates = require('metalsmith-templates');

metalsmith(__dirname)
  .source('./src')
  .destination('./dest')
  .use(autotoc({selector: 'h2, h3, h4'}))
  .use(templates({
    engine: 'eco',
    directory: './templates'
  }))
  .build();

Results file dest/index.html:


<ol class="toc">
  <li><a href="#aaa">aaa</a>
    <ol class="toc">
      <li><a href="#bbb">bbb</a></li>
      <li><a href="#ccc">ccc</a></li>
    </ol>
  </li>
  <li><a href="#ddd">ddd</a></li>
</ol>

<h2 id="aaa">aaa</h2>
<p>paragraph</p>

<h3 id="bbb">bbb</h3>
<p>paragraph</p>

<h3 id="ccc">ccc</h3>
<p>paragraph</p>

<h2 id="ddd">ddd</h2>
<p>paragraph</p>

License

MIT

metalsmith-autotoc's People

Contributors

anatoo avatar dannon avatar meshulam avatar mplewis avatar williamwilling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

metalsmith-autotoc's Issues

Documentation for other template languages

The example in the README is for .eco templates, but I can't see how exactly it'd work with Handlebars or AN Other templating language - can you update the docs with a little example?

Duplicate IDs

I'm having an issue on my site where duplicate IDs are created when there are two headings with the same inner text.

<h2 id="first">First</h2>
<h3 id="overview">Overview</h3>
<h2 id="second">Second</h2>
<h3 id="overview">Overview</h3>

Would you consider adding something to make these unique? Perhaps like appending an index number.

<h2 id="first">First</h2>
<h3 id="overview">Overview</h3>
<h2 id="second">Second</h2>
<h3 id="overview2">Overview</h3>

Thanks!

Install issues related to Node 4.x

Seems the "Contextify" dependency has issues with recent Node versions, as noted here:

brianmcd/contextify#180

I'm not sure how to fix this, only discovering it when I tried to install this plugin today. Might there be a workaround for this module so that it could be installed?

possibility to use another templating engine?

It appears that this plugin seems to be linked to eco rendering engine.

Could it be possible to use another templating engine such as handlebars?

This could be the opportunity to switch from metalsmith-template to metalsmith-layout.

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.