https://github.com/assemble/assemble-collections
Node library to manage collections of objects in or out of Assemble.
https://github.com/assemble/assemble-collections
Last synced: 11 months ago
JSON representation
Node library to manage collections of objects in or out of Assemble.
- Host: GitHub
- URL: https://github.com/assemble/assemble-collections
- Owner: assemble
- License: mit
- Created: 2014-04-14T20:02:04.000Z (about 12 years ago)
- Default Branch: master
- Last Pushed: 2016-04-20T19:37:14.000Z (about 10 years ago)
- Last Synced: 2025-07-03T01:38:24.364Z (11 months ago)
- Language: JavaScript
- Size: 56.6 KB
- Stars: 5
- Watchers: 11
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# assemble-collections [](https://www.npmjs.com/package/assemble-collections) [](https://travis-ci.org/assemble/assemble-collections)
> Assemble plugin to add middleware and helpers for working with frontmatter based collections.
## Install
Install with [npm](https://www.npmjs.com/):
```sh
$ npm install assemble-collections --save
```
**WARNING**
> This library has changed to be an assemble plugin as of version 0.2.0.
## Usage
```js
var collections = require('assemble-collections');
var app.use(collections());
```
## API
### [.collections](index.js#L23)
Add middleware to gather collections from frontmatter and provide helpers for working with collections, collection groups, and views in collection groups.
**Params**
* `config` **{Object}**: Configuration object for setting up frontmatter collections.
* `config.exts` **{Array}**: Array of extensions to use when adding `preRender` middleware. Defaults to `['md', 'hbs', 'html']`.
* `config.collections` **{Object}**: Optional collections to look for in view frontmatter. Default collections are `categories` and `tags`.
* `config.collections.${key}` **{Object}**: Individual collection configuration.
* `config.collections.${key}.inflection` **{String}**: Singular version of collection key: e.g. `categories: { inflection: 'category' }`
* `config.collections.${key}.sortOrder` **{String}**: Default sort direction of views in each collection. Defaults to `asc`.
**Example**
```js
app.use(collections());
```
### [collections](index.js#L114)
Helper to iterate or return an array of frontmatter collection keys.
**Example**
```handlebars
{{! use as a block helper }}
{{#collections}}
{{this.name}}
{{/collections}}
{{! use as a subexpression }}
{{#each (collections)}}
{{this.name}}
{{/each}}
```
### [collection](index.js#L153)
Helper to return the collection instance or iterate over each collection item in the collection.
**Example**
```handlebars
{{! use as a block helper }}
{{#collection "categories"}}
{{category}}
- {{name}}
{{#each items}}
{{/each}}
{{/collection}}
{{! use as a subexpression }}
{{#each (collection "categories")}}
{{category}}
- {{name}}
{{#each items}}
{{/each}}
{{/each}}
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/doowb/assemble-collections/issues/new).
## Building docs
Generate readme and API documentation with [verb](https://github.com/verbose/verb):
```sh
$ npm install verb && npm run docs
```
Or, if [verb](https://github.com/verbose/verb) is installed globally:
```sh
$ verb
```
## Running tests
Install dev dependencies:
```sh
$ npm install -d && npm test
```
## Author
**Brian Woodward**
* [github/doowb](https://github.com/doowb)
* [twitter/doowb](http://twitter.com/doowb)
## License
verb © 2016, [Brian Woodward](https://github.com/doowb).
Released under the [MIT license](https://github.com/assemble/assemble-collections/blob/master/LICENSE).
***
_This file was generated by [verb](https://github.com/verbose/verb), v0.9.0, on April 20, 2016._