Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/ericgj/metalsmith-branch
A metalsmith plugin to run separate middleware pipelines on selected files.
https://github.com/ericgj/metalsmith-branch
Last synced: about 2 months ago
JSON representation
A metalsmith plugin to run separate middleware pipelines on selected files.
- Host: GitHub
- URL: https://github.com/ericgj/metalsmith-branch
- Owner: ericgj
- Created: 2014-04-06T01:44:39.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2016-12-13T16:57:06.000Z (about 8 years ago)
- Last Synced: 2024-11-10T19:56:44.376Z (2 months ago)
- Language: JavaScript
- Homepage:
- Size: 12.7 KB
- Stars: 20
- Watchers: 3
- Forks: 5
- Open Issues: 1
-
Metadata Files:
- Readme: Readme.md
Awesome Lists containing this project
README
# metalsmith-branch
A [metalsmith][metalsmith] plugin to run separate middleware pipelines on
selected files.Facilitates 'declarative' pipelines by file pattern or filter, since it means
each plugin doesn't have to implement its own filtering. See examples below.*April 2014: Please bear in mind that this is 0.0.x software and use with
caution, especially since metalsmith itself is likely to change.*## Installation
$ npm install metalsmith-branch
## Usage
In your build file:
```js
var branch = require('metalsmith-branch')metalsmith
.use( branch()
.pattern('*.md') // for only md source files,
.use( templates({ // run through swig template engine
engine: "swig",
inPlace: true
})
)
.use( markdown() ) // and generate html
)// you can also specify the pattern directly in constructor
metalsmith
.use( branch('images/*')
.use( imageVariants() )
)// or select files by function of their name, properties, and order:
var lastweek = function(filename,props,i){
var dt = new Date()
, last = new Date( dt.getFullYear(), dt.getMonth(), dt.getDate());
last.setDate( last.getDate() - 6 )
return ( props.published >= last );
}metalsmith
.use( branch( lastweek )
.use( tagLatest() )
)
```Note that nested branches are possible too.
```js
// to post-process only markdown-sourced files in a 'special' dir:metalsmith
.use( branch('*.md')
.use( markdown() )
.use( branch('special/*.html')
.use( postProcess() )
)
)
```
It's also possible to specify an array of patterns:
```js
// to select all markdown files in the "posts" and "projects" directories:metalsmith
.use( branch()
.pattern(["projects/*/*.md", "posts/**/*.md"])
.use( markdown() )
)
```
See [multimatch][multimatch] for all pattern options.
## LicenseMIT
[metalsmith]: https://github.com/segmentio/metalsmith
[multimatch]: https://www.npmjs.com/package/multimatch