Created
June 18, 2019 01:37
-
-
Save praveensewak/2d23227cb3546c45580373e7e0290e20 to your computer and use it in GitHub Desktop.
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
var fs = require('fs') | |
var cleaner = require('clean-html') | |
function readFiles(dir, onFileContent, onError) { | |
fs.readdir(dir, function (err, filenames) { | |
if (err) { | |
onError(err) | |
return | |
} | |
filenames.forEach(function (filename) { | |
fs.readFile(dir + filename, 'utf-8', function (err, content) { | |
if (err) { | |
onError(err) | |
return | |
} | |
onFileContent(filename, content) | |
}) | |
}) | |
}) | |
} | |
var data = {} | |
var options = { | |
'add-remove-tags': ['html', 'head', 'meta', 'style', 'body', 'span', 'div'], | |
'remove-empty-tags': ['div', 'p'], | |
'replace-nbsp': true, | |
'add-remove-attributes': ['class', 'id'] | |
} | |
readFiles('source\\', function (filename, content) { | |
data[filename] = content | |
console.log(filename) | |
cleaner.clean(content, options, function (html) { | |
fs.writeFile('output\\' + filename, html, function (err) { | |
if (err) { | |
console.log(err) | |
return | |
} | |
}) | |
}) | |
}, function (err) { | |
throw err | |
}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment