Created
July 8, 2019 05:23
-
-
Save violetyk/4dfb1edc8397d2ddf5e9e3db66356ade to your computer and use it in GitHub Desktop.
配下のmdをpdfにする
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/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