Skip to content

Instantly share code, notes, and snippets.

@aronwoost aronwoost/index.js
Created Dec 12, 2013

Embed
What would you like to do?
Octopress. Extract date from filename and add to post header.
var fs = require("fs");
var async = require("async");
var folder = "source/_posts";
fs.readdir(folder, function(err, result) {
async.each(result, function(file, callback){
var date = file.split("-").slice(0, 3).join("-"),
dateStr = "date: "+date+" 00:00:00 +0100";
fs.readFile(folder + "/" + file, "UTF-8", function read(err, content) {
if(err) {
return console.log(err);
}
var newContent = content.split("layout: post").join("layout: post\n" + dateStr);
fs.writeFile(folder + "/" + file, newContent, function(err) {
if(err) {
return console.log(err);
}
console.log("The file was saved!");
callback();
});
});
}, function(err){
if(err) {
return console.log(err);
}
console.log("done");
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.