metalsmith / headings

A Metalsmith plugin that extracts headings from HTML files and attaches them to the file's metadata.
22 stars 8 forks source link

fix(sorting): Fixes the return type being ordered by selector, not position in document #5

Closed zakhenry closed 7 years ago

zakhenry commented 8 years ago

This changes the selection so the matches are returned in their natural order from the document, not the order that the selectors were listed.

Now it is possible to make multi level menus. Example with handlebars: Metalsmith config:

Metalsmith('test/fixture')
      .use(markdown())
      .use(headings({ selectors: ['h2', 'h3']}))
      .build();

Template:

<ul class="section table-of-contents">
      {{#each headings }}
          <li><a href="#{{ id }}">{{{ifEqual tag 'h3' '&emsp;' }}}# {{ text }}</a></li>
      {{/each}}   
</ul>

Outputs:

# Getting started
# Adding pages
 # Collections
 # Templates & Partials
 # Styles & Assets
 # Variables
# TypeDoc
# Deployment
 # Config
 # Travis CI
# Plugins

Closes #4

oupala commented 8 years ago

Great news. I'm looking forward to see this pull request merged!

zakhenry commented 8 years ago

@oupala if you want to use the feature now - install @xiphiaz/metalsmith-headings - it's just my unmerged fork

mentos1386 commented 8 years ago

Would be nice to see this pull request merged.

oupala commented 7 years ago

Thanks a lot @zakhenry !

I'm using your fork as the pull request has not been merged until now.

oupala commented 7 years ago

Very good news, thanks a lot!