Skip to content

Instantly share code, notes, and snippets.

@violetyk
Created July 8, 2019 05:23
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 violetyk/4dfb1edc8397d2ddf5e9e3db66356ade to your computer and use it in GitHub Desktop.
Save violetyk/4dfb1edc8397d2ddf5e9e3db66356ade to your computer and use it in GitHub Desktop.
配下のmdをpdfにする
#!/usr/bin/env node
const
fs = require('fs'),
path = require('path'),
markdownpdf = require('markdown-pdf');
const walk = (dir, callback) => {
fs.readdirSync(dir).forEach((item) => {
const filePath = path.join(dir, item);
const stat = fs.statSync(filePath);
if (stat.isDirectory()) {
walk(filePath, callback);
} else if (stat.isFile()) {
callback(filePath);
}
});
}
const
src = './docs';
dest = './tmp/pdf';
options = {
"paperFormat": 'A4'
};
walk('./docs', filePath => {
if (/.*\.md$/.test(filePath)) {
const p = path.parse(filePath);
const output = `${dest}/${p.dir}/${p.name}.pdf`;
markdownpdf(options)
.from(filePath)
.to(output, function() {
console.log(output);
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment