sparkartgroup / gulp-markdown-to-json

Parse Markdown and YAML → compile Markdown to HTML → wrap it all up in JSON
MIT License
75 stars 14 forks source link

Append additional key:value to single file style. #9

Closed tomgenoni closed 8 years ago

tomgenoni commented 9 years ago

Thanks for the script. This is great. Had one question: in addition to the front-matter content I wanted to pass in the path to the file — file.path — so that with each entry in the resulting json there'd be a "path":"/path/to/file.md". Is that possible?

pushred commented 8 years ago

Apologies for the super belated response. For the one year anniversary (!) of your question I added an optional transform function (#14) that passes the Vinyl object which provides this property. This approach (vs. config) has been super helpful for me in other plugins where I've had similar needs.

To add it to the JSON output:

gulp.src('./content/**/*.md')
  .pipe(gutil.buffer())
  .pipe(markdownToJSON(marked, (data, file) => {
    data.path = file.path;
    return data;
  }))
  .pipe(gulp.dest('.'))
pushred commented 8 years ago

This was published as 1.0.0, closing for now, feel free to reopen if you've got any feedback