Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How can i append the data to an existing JSON file? #22

Open
talvasconcelos opened this issue Jul 18, 2016 · 1 comment
Open

How can i append the data to an existing JSON file? #22

talvasconcelos opened this issue Jul 18, 2016 · 1 comment

Comments

@talvasconcelos
Copy link

Hi, how can i append the data i get from front-matter to an existing json file? Here's what i have:

`gulp.task('meta', function(){
return gulp.src(path.posts)
.pipe(plumber({
handleError: onError
}))
.pipe(frontMatter({ property: 'meta'}))
//.pipe(data(function(file){
// file.meta.path = file.path
// }))
.pipe(pluck('meta', 'meta.json'))
.pipe(data(function(file){
file.contents = new Buffer(JSON.stringify({'articles': file.meta}, null, ' '));
//var obj = JSON.parse(require './config.json');
//obj.articles = file.contents;

}))
.pipe(gulp.dest('dev/articles/'))

});`

At the moment it outputs to a meta.json file, i'd like for it to append the data to an existing config.json under an "artilcles" key.

Thanks,
Tiago

@ghost
Copy link

ghost commented Feb 8, 2017

This is from my project and works well.

  1. Append static json
  2. Append currFile
  3. Append GrayMatter Data (works same as FrontMatter)
      .pipe(plugins.data(function (file) {
        let data = JSON.parse(fs.readFileSync(cacheFile));
        data.currFile = path.basename(file.path);
        return data;
      }))
      .pipe(plugins.grayMatter())

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant