Created
November 28, 2021 11:36
-
-
Save amir-arad/dbbe5a63f17df6041ada0a1937ed18f6 to your computer and use it in GitHub Desktop.
convert folder of markdown files to google docs in windows
This file contains 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
const fs = require('fs'); | |
const path = require('path'); | |
var execSync = require('child_process').execSync; | |
const getAllFiles = function (dirPath, arrayOfFiles) { | |
files = fs.readdirSync(dirPath); | |
arrayOfFiles = arrayOfFiles || []; | |
files.forEach(function (file) { | |
if (fs.statSync(dirPath + '/' + file).isDirectory()) { | |
arrayOfFiles = getAllFiles(dirPath + '/' + file, arrayOfFiles); | |
} else if (file.endsWith('.md')) { | |
arrayOfFiles.push(path.join(dirPath, '/', file)); | |
} | |
}); | |
return arrayOfFiles; | |
}; | |
for (const file of getAllFiles('C:\\temp\\src')) { | |
console.log(file); | |
fs.mkdirSync(path.dirname(file.replace('C:\\temp\\src', 'C:\\temp\\dist')), { recursive: true }); | |
const srcPath = file.replace('C:\\temp\\src', './src').split(path.sep).join(path.posix.sep); | |
const distPAth = file | |
.replace('C:\\temp\\src', './dist') | |
.replace('.md', '.odt') | |
.split(path.sep) | |
.join(path.posix.sep); | |
execSync(`docker run --rm -v C:/temp:/data pandoc/core "${srcPath}" -f markdown -t odt -o "${distPAth}"`, { | |
stdio: 'inherit', | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment