Skip to content

Instantly share code, notes, and snippets.

@jou
Created June 4, 2010 13:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jou/425406 to your computer and use it in GitHub Desktop.
Save jou/425406 to your computer and use it in GitHub Desktop.
/* Simple node.js script to automatically generate HTML from Markdown files whenever
* they are changed. Requires [node-glob][1]. TODO: Watch for new files.
*
* [1]: http://github.com/isaacs/node-glob
*/
var fs = require('fs'),
sys = require('sys'),
path = require('path'),
spawn = require('child_process').spawn,
glob = require('./glob').glob,
generateHtml = function(f) {
var target = path.join('html', path.basename(f, '.markdown')+'.html' )
maruku = spawn('maruku', ['-o', target, '--html', f]);
maruku.stderr.addListener('data', function(data) {
sys.print("stderr: ", data);
});
maruku.addListener('exit', function(code) {
if (code == 0) {
sys.puts(f + " => " + target);
} else {
sys.puts(f + " failed");
}
});
};
glob('*.markdown').forEach(function(f) {
sys.puts('Watching ' + f);
sys.puts('generate ' + f);
generateHtml(f);
fs.watchFile(f, function(curr, prev) {
if (curr.mtime > prev.mtime) {
sys.puts("regenerate " + f);
generateHtml(f);
}
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment