https://github.com/assemble/assemble-indexer
Templates plugin to add index views to template collections.
https://github.com/assemble/assemble-indexer
Last synced: about 1 year ago
JSON representation
Templates plugin to add index views to template collections.
- Host: GitHub
- URL: https://github.com/assemble/assemble-indexer
- Owner: assemble
- License: mit
- Created: 2015-09-10T05:50:48.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2015-12-18T17:10:37.000Z (over 10 years ago)
- Last Synced: 2025-03-23T00:05:04.880Z (about 1 year ago)
- Language: JavaScript
- Size: 31.3 KB
- Stars: 7
- Watchers: 11
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# assemble-indexer [](http://badge.fury.io/js/assemble-indexer) [](https://travis-ci.org/assemble/assemble-indexer)
> Assemble plugin to add index views to template collections.
Install with [npm](https://www.npmjs.com/)
```sh
$ npm i assemble-indexer --save
```
## Usage
```js
var indexer = require('assemble-indexer');
```
## API
### [indexer](index.js#L29)
Add `addIndices` to a [templates](https://github.com/jonschlinkert/templates) collection that will add index views to the collection when given an array of pages.
**Params**
* `options` **{Object}**
* `options.index` **{Object}**: Optional instance of `View` to use as the basis for the index views being added. Required if `createView` is not passed on plugin or method options.
* `options.createView` **{Function}**: Function to create a view instance for the index view being added. Required if `index` is not passed on plugin or method options.
* `returns` **{Function}**: Function to use as a plugin for [templates](https://github.com/jonschlinkert/templates)
**Example**
```
var archives = app.create('archives')
.use(indexer())
.addIndices(pages);
```
### .addIndices
`addIndices` method decorated onto the given `collection` Iterators over a list of `pages` (built with `list.paginate`) and adds each page to the collection as a new index view
**Params**
* `pages` **{Array}**: Array of pages return from `list.paginate`
* `opts` **{Object}**: Method options to override plugin options. Will also be added to locals for each index view.
* `opts.index` **{Object}**: Optional instance of `View` to use as the basis for the index views being added. Required if `createView` is not passed on plugin or method options.
* `opts.createView` **{Function}**: Function to create a view instance for the index view being added. Required if `index` is not passed on plugin or method options.
* `returns` **{Object}**: Returns `collection` to enable chaining
**Example**
```js
collection.addIndices(pages, locals);
```
## Related projects
* [assemble](https://www.npmjs.com/package/assemble): Static site generator for Grunt.js, Yeoman and Node.js. Used by Zurb Foundation, Zurb Ink, H5BP/Effeckt,… [more](https://www.npmjs.com/package/assemble) | [homepage](http://assemble.io)
* [paginationator](https://www.npmjs.com/package/paginationator): Paginate an array into pages of items. | [homepage](https://github.com/doowb/paginationator)
* [template](https://www.npmjs.com/package/template): Render templates using any engine. Supports, layouts, pages, partials and custom template types. Use template… [more](https://www.npmjs.com/package/template) | [homepage](https://github.com/jonschlinkert/template)
* [templates](https://www.npmjs.com/package/templates): System for creating and managing template collections, and rendering templates with any node.js template engine.… [more](https://www.npmjs.com/package/templates) | [homepage](https://github.com/jonschlinkert/templates)
## Running tests
Install dev dependencies:
```sh
$ npm i -d && npm test
```
## Contributing
Pull requests and stars are always welcome. For bugs and feature requests, [please create an issue](https://github.com/assemble/assemble-indexer/issues/new).
## Author
**Brian Woodward**
+ [github/doowb](https://github.com/doowb)
+ [twitter/doowb](http://twitter.com/doowb)
## License
Copyright © 2015 Brian Woodward
Released under the MIT license.
***
_This file was generated by [verb-cli](https://github.com/assemble/verb-cli) on September 20, 2015._