Skip to content

Instantly share code, notes, and snippets.

@amir-arad
Created November 28, 2021 11:36
Show Gist options
  • Save amir-arad/dbbe5a63f17df6041ada0a1937ed18f6 to your computer and use it in GitHub Desktop.
Save amir-arad/dbbe5a63f17df6041ada0a1937ed18f6 to your computer and use it in GitHub Desktop.
convert folder of markdown files to google docs in windows
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