npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

navigation-helpers

v0.3.1

Published

Template helpers for Assemble-Navigation

Downloads

4

Readme

navigation-helpers

Template helpers for Assemble Navigation

Assemble-Navigation is a middleware collection for use with Assemble to generate and inject hierarchal navigation data into a page's context. That page can then use a template or partial to build any kind of menu.

This collection of template helpers compliments Assemble-Navigation making it easier to create menus and breadcrumb trails.

See Assemble-Navigation's readme for more information on menu schemas and how to use them.

Note: a demo site for Assemble-Navigation and these helpers are in the works. That site will also have some more in-depth tutorials.

Helpers

handlebars-collectionquery

Block helper for querying menus and selecting the children of a submenu. Will create an array of menu items that can then be rendered. Includes sorting.

Sample Usage

Parameters

  • collection (array of menuitems) you want to search. Typically, you'll want to query the top items array of a menu (navigation.main.items, navigation.footer.items, etc.).
  • key (string): the object property you want to search on.
  • inlist (string): works like key but will inspect teh given array attribute for any matches to value
  • value (string|number): what that key should equal, this uses strick equals (===) so make sure you're using the same type
  • sortBy (string): optional sorting attribute
  • sortDir (string): optional sort order (asc, desc)
  • property ('string'): determines what is passed to the inner block. If you just want the matching menu item, leave this out. If you want the children menu items of the matching block, use 'items'.
  • includeParent (boolean): When using property, the index page (AKA the parent) is left out of the results by default. Set this to true to include the parent in the items passed to the inner template.

key and sortBy should be able to use nested property paths ('a.b.c') to access nested hashes. This was added to preform queries on Assemble view collections as well as menu-item collections.

<ul class="sidebar-menu">
  {{#collectionQuery navigation.main.items key='linkId' value='about-index' includeParent=true property='items' sortBy='title' sortDir='asc'}}
  <li><a href="{{{url}}}" >{{{title}}}</a></li>
{{/collectionQuery}}
<ul>

breadcrumb

This helper parses a navigation menu and returns any items in the current page's active path (the page and it's parent, grandparent, etc.) to the inner block.

You can then output them using in any format you like.

{{#breadcrumb navigation.main}}
    {{#if isActive}}
       <a href='{{url}}'>{{title}}</a> &raquo;
    {{else}}
        {{title}}
    {{/if}}
{{/breadcrumb}}

Using with Assemble

If you have Assemble and Assemble Navigation already setup and working, then you just need to configure the helper.

Install via npm...

npm i navigation-helpers --save

Add the helper to Assemble..

app.helpers(require('navigation-helpers'));

Release History

v0.3.1

Backward compatible changes to collectionQuery helper to give it the ability to filter by matching array properties using the inlist parameter.

v0.2.0

Backward compatible changes to collectionQuery helper to give it the ability to filter based on nested properties.

v0.1.0

Beta release. Future releases will likely add new helpers. I'd expect the APIs for existing helpers to remain the same.

Contributing and Issues

Feel free to submit issues or pull requests for Navigation-Helpers. Questions on use can also be submitted to the issue queue.

There's a suite of unit tests. mocha test/*-spec.js

License

© 2016 John O'Donnell (Critical Mash Inc.) Released under the MIT license.