Created
December 12, 2013 10:41
-
-
Save aronwoost/7926103 to your computer and use it in GitHub Desktop.
Octopress. Extract date from filename and add to post header.
This file contains 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 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