Created
February 4, 2014 04:50
-
-
Save wlaurance/8798326 to your computer and use it in GitHub Desktop.
json header to yaml header
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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