Created
September 13, 2013 18:57
-
-
Save seykron/6554651 to your computer and use it in GitHub Desktop.
Update nanoc blog posts reading content from etherpad. Usage: ./updatePost.js post entry-name It assumes posts are named in etherpad by using the following convention: post!entry-name
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
#!/usr/bin/node | |
var fs = require("fs"); | |
var api = require('etherpad-lite-client'); | |
var eth = api.connect({ | |
apikey: 'your-api-key', | |
host: 'localhost', | |
port: 9001 | |
}); | |
var contentType = process.argv[2]; | |
var padId = process.argv[3]; | |
var PATH = { | |
post: "./content/posts/", | |
story: "./content/stories/" | |
}; | |
if (!contentType || !padId) { | |
console.log("Content type and Pad ID must be specified"); | |
process.exit(1); | |
} | |
console.log("Updating pad: " + padId); | |
eth.getText({ | |
padID: contentType + "!" + padId | |
}, function (err, pad) { | |
var SEP = "======="; | |
var post; | |
var file = PATH[contentType] + padId + ".md"; | |
if (err) { | |
console.log(err); | |
return; | |
} | |
post = pad.text.substr(pad.text.indexOf(SEP) + SEP.length + 1); | |
fs.writeFileSync(file, post); | |
console.log("Pad updated: " + file); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment