https://github.com/simbo/gulp-gray-matter
A gulp plugin for extracting data header from file contents using gray-matter.
https://github.com/simbo/gulp-gray-matter
Last synced: about 1 year ago
JSON representation
A gulp plugin for extracting data header from file contents using gray-matter.
- Host: GitHub
- URL: https://github.com/simbo/gulp-gray-matter
- Owner: simbo
- License: mit
- Created: 2016-02-03T20:21:54.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2019-01-29T02:32:45.000Z (over 7 years ago)
- Last Synced: 2025-06-10T08:06:19.436Z (about 1 year ago)
- Language: JavaScript
- Homepage:
- Size: 16.6 KB
- Stars: 3
- Watchers: 2
- Forks: 3
- Open Issues: 4
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
gulp-gray-matter
================
> A *gulp* plugin for extracting data header from file contents using *gray-matter*.
> *"See the [benchmarks](https://www.npmjs.com/package/gray-matter#benchmarks). gray-matter is 20-30x faster than front-matter."*
> ([@jonschlinkert](https://www.npmjs.com/~jonschlinkert))
[](https://www.npmjs.com/package/gulp-gray-matter)
[](http://simbo.mit-license.org)
[](https://travis-ci.org/simbo/gulp-gray-matter)
[](https://codecov.io/github/simbo/gulp-gray-matter)
[](https://david-dm.org/simbo/gulp-gray-matter)
[](https://david-dm.org/simbo/gulp-gray-matter#info=devDependencies)
---
- [About](#about)
- [Setup and usage](#setup-and-usage)
- [Options](#options)
- [property](#property)
- [remove](#remove)
- [trim](#trim)
- [setData](#setdata)
- [License](#license)
---
## About
*gulp-gray-matter* is a plugin for [gulp](http://gulpjs.com/), to extract data
headers from file contents using [gray-matter](https://www.npmjs.com/package/gray-matter).
The extracted data is set as a property of the file object for further processing.
You can customize the property name and also use nested properties (via
[object-path](https://www.npmjs.com/package/object-path)).
If the file object already has data attached on the defined property, existing
data will be merged recursively with extracted data (using
[merge](https://www.npmjs.com/package/object-path)). You can define a custom
function for setting data to change this behavior.
There are further [custom options](#options) and of course you can also use all
[gray-matter options](https://www.npmjs.com/package/gray-matter#options).
## Setup and usage
Install `gulp-gray-matter` using `npm`:
```sh
npm i gulp-gray-matter
```
In your `gulpfile.js`:
```js
var gulp = require('gulp'),
gulpGrayMatter = require('gulp-gray-matter');
gulp.task('default', function() {
return gulp.src('./src/**.*')
.pipe(gulpGrayMatter({ /* options */ }))
// …
.pipe(gulp.dest('./dest'));
});
```
A common workflow, after extracting front matter, could be using a template
rendering plugin like [gulp-jade](https://www.npmjs.com/package/gulp-jade).
## Options
Beside its own options, *gulp-gray-matter* also supports all
[gray-matter options](https://www.npmjs.com/package/gray-matter#options):
`delims`, `eval`, `lang` and `parser`
### property
*String*
Default: `'data'`
The file object property for setting data. can also be a nested property name
like `foo.bar.baz`.
### remove
*Boolean*
Default: `true`
Whether data header should be removed from file contents or not.
### trim
*Boolean*
Default: `true`
Whether file contents should be trimmed after removing file header or not.
(has no effect if `options.remove` is `false`.)
### setData
*Function*
Default:
```js
function setData(oldData, newData) {
return require('merge').recursive(oldData, newData);
}
```
If there is already data attached to the file object on the property defined
with `options.property`, existing data will be recursively merged with extracted
data. Set your own function to change this behavior.
## License
[MIT © 2016 Simon Lepel](http://simbo.mit-license.org/)
Before version 2.2.2, [@jakwings](https://www.npmjs.com/~jakwings) was the
original author and owner of the npm package *gulp-gray-matter*.