Skip to content

Instantly share code, notes, and snippets.

@finalclass
Created February 14, 2013 22:14
Show Gist options
  • Save finalclass/4956903 to your computer and use it in GitHub Desktop.
Save finalclass/4956903 to your computer and use it in GitHub Desktop.
Join .md (markdown) files in directory and save it to build.md file.
#!/usr/local/bin/node
var fs = require('fs');
fs.readdir(__dirname, function (err, files) {
var contents = [],
mdFiles;
mdFiles = files.filter(function (file) {
return file.substr(-3) === '.md' &&
file !== 'build.md';
});
mdFiles.sort();
mdFiles.forEach(function (file, index) {
contents.push(fs.readFileSync(file, 'utf-8'));
});
fs.writeFile(__dirname + '/build.md', contents.join('\n\n'));
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment