Skip to content

Instantly share code, notes, and snippets.

@wlaurance
Created February 4, 2014 04:50
Show Gist options
  • Select an option

  • Save wlaurance/8798326 to your computer and use it in GitHub Desktop.

Select an option

Save wlaurance/8798326 to your computer and use it in GitHub Desktop.
json header to yaml header
var fs = require('fs');
var YAML = require('json2yaml');
var layout = process.env.JEKYLL_POST_LAYOUT || "post";
process.stdin.on('data', function(d) {
var files = d.toString().split('\n').filter(function(e){ return e !== ''; });
files.map(function(fn) {
var contents = fs.readFileSync(fn).toString();
contents.replace(/({.*title.*})/m, function(match, p1, s) {
var blob = JSON.parse(p1);
blob.layout = layout;
var yamlblob = YAML.stringify(blob) + '---\n';
fs.writeFileSync(fn, contents.replace(p1, yamlblob));
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment