- Notifications
You must be signed in to change notification settings - Fork0
A Grunt task for extracting data header from file contents using Gray Matter
License
ArmorDarks/grunt-gray-matter
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
A Grunt task for extracting data header from file contents using Gray Matter
If you haven't usedGrunt before, be sure to check out theGetting Started guide, as it explains how to createaGruntfile as well as install and use Grunt plugins.
Install plugin with following command:
npm install grunt-gray-matter --save
Once installed, eenable task inside your Gruntfile:
grunt.loadNpmTasks('grunt-gray-matter')
Add minimal configuration for task in Gruntfile:
grunt.initConfiggrayMatter:build:src:'source/templates/{,**/}*.html'dest:'data/matter.json'
Finally, run task with following command:
grunt grayMatter
Task scans specified infiles
src
files, reads Gray Matter (Front Matter) header withGray Matter and outputs collected result in form of JSON to specifieddest
file.
Path of each discoveredsrc
will serve as property in final JSON for extracted Gray Matter data of thatsrc
.
Type:String
Default:''
Path portion which should be subtracted from path to discoveredsrc
file.
Result will be used indest
file JSON as property of extracted Gray Matter data.
@config'grayMatter',build:options:baseDir:'source/templates'src:'source/templates/page.html'dest:'matter.json'
Will result in
{"page": {"html": {... }, }}
instead of
{"source/templates/page": {"html": {... }, }}
Type:Function
Default:undefined
Allows to alter path (property) under which extracted Matter data will be placed indest
JSON file.
Nesting will be done with_.set, thus any.
in path or array of strings will result in nesting data deeper.
You can seehere as Kotsu uses this option to mirror templates directory structure in final JSON.
Will be invoked with injected values for following arguments:
path
— formed after subtractingoptions.baseDir
path of currentsrc
, used to nest data in final JSON;filepath
— filepath of currentsrc
.
this
will correspond to currentfile
of task.
Should return altered path in form ofString
orString[]
.
Type:Function
Default:undefined
Allows to alter extracted Gray Matter data for each discoveredsrc
.
As for an example, check out how Kotsuinjects additional data for each page into final Matter data.
Will be invoked with injected values for following arguments:
matterData
— extracted Matter data of currentsrc
;path
— formed after subtractingoptions.baseDir
path of currentsrc
, used to nest data in final JSON;filepath
— filepath of currentsrc
.
this
will correspond to currentfile
object.
Should return altered Gray Matter data in form ofObject
.
Type:Function
Default:undefined
Allows to alter final data, constructed from extracted Matter data.
Result of this function will be used for printing Object todest
file.
Will be invoked with injected values for following arguments:
data
— extracted and assembled data from all currentsrc
es Matter data, processed bypreprocessPath
andpreprocessMatterData
(if specified).
this
will correspond to currentthis
of task.
Should return altered final data in form ofObject
, which will be printed todest
file.
Type:Function|String[]|Number[]
Default:null
Passreplacer parameter toJSON.stringify()
.
Type:String|Integer
Default:2
Passspace parameter toJSON.stringify()
.
Controls indentation for outputted JSON file.
Type:Function
Default:undefined
Passcustom parser to Gray Matter.
Type:Boolean
Default:false
Passeval parameter to Gray Matter.
Forces Gray Matter to evaluate CoffeeScript or JavaScript in Front Matter.
Type:String
Default:undefined
Passlang parameter to Gray Matter.
Type:String
Default:undefined
Passdelims parameter to Gray Matter.
@config'grayMatter',build:options:baseDir:'source/templates'preprocessPath: (path)-># do something with paths in constructed json filereturn pathpreprocessMatterData: (data,path,src)-># do something with extracted datareturn datasrc:'source/templates/{,**/}*.html'dest:'data/matter.json'
Requires Node 6.0 or higher.
Just in case,grunt-gray-matter
1.2.0 was the last version to support Node 0.10.0. But better go update your Node. Seriously.
Runnpm test
to launch tests ornpm run test:watch
to watch tests. Observe how magic happens.
Testing requires Node >= 4.0.0.
Copyright 2016 Serj Lavrin.
Licensed under theApache 2.0 license.
About
A Grunt task for extracting data header from file contents using Gray Matter
Topics
Resources
License
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.