Skip to content

Instantly share code, notes, and snippets.

@jacebenson
Last active November 26, 2018 16:41
Show Gist options
  • Save jacebenson/f6eba3a293def19bf8184defbf274dcc to your computer and use it in GitHub Desktop.
Save jacebenson/f6eba3a293def19bf8184defbf274dcc to your computer and use it in GitHub Desktop.
Output pandoc command
// just run node pandoc-build.js > output.txt
// that will write the contents of this there
// and then just copy paste that command and
// you should get a good epub.
// I always had to cd to the root of the posts
// directory to run the command.
var fs = require('fs');
var path = require('path');
var output = [
"pandoc -o _book.epub \\\n",
"--toc \\\n",
"--toc-depth=1 \\\n",
"--epub-cover-image=adi-goldstein-257316-unsplash.jpg \\\n",
"title.md \\\n"
];
var pathsForImages = [".","."];
var blogFolders = "./blog"
fs.readdir(blogFolders, function (err, folders) {
if (err) {
console.error("Could not list directory", err);
}
folders.forEach(function (folder, index) {
var folderPath = path.join(blogFolders, folder);
fs.stat(folderPath, function (error, stat) {
if (error) {
console.error('Stat error', error);
}
if (stat.isDirectory()) {
//console.log('adding ' + folderPath);
output.push(folderPath + "/index.md \\\n")
pathsForImages.push(folderPath);
}
//console.log(index + ' / ' + folders.length);
if(index == (folders.length-1)){
pathsForImages = pathsForImages.join(":");
pathsForImages = pathsForImages.replace(/\\/gm,'/');
output = output.join(" ");
output += " --resource-path=" + pathsForImages;
output = output.replace(/\sblog\\/gm, 'blog/');
output = output.replace(/\s\n\s\\/gm, '\n');
console.log(output);
}
});
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment