-
Notifications
You must be signed in to change notification settings - Fork 8
/
helpcenter-cleaner.js
45 lines (35 loc) · 1.01 KB
/
helpcenter-cleaner.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
const fs = require('fs');
const path = require('path');
const directoryPath = path.join(__dirname, '.');
function isDirectory(p) {
return fs.lstatSync(p).isDirectory()
}
function readDir(dirpath) {
fs.readdir(dirpath, function (err, itens) {
if (err) {
console.log('Unable to scan directory: ' + err);
return;
}
itens.forEach(function (item) {
let path = `${dirpath}/${item}`;
if (!path.includes("src")) {
return
}
if(isDirectory(path)) {
readDir(path);
return
}
if (!path.includes("includes")) {
return
}
if (!path.includes("docs_help_center")) {
return
}
const buffer = fs.readFileSync(path);
const content = buffer.toString('utf-8');
const text = content.replace(/{: target="_blank"}/g, '');
fs.writeFileSync(path, text, 'utf-8');
});
});
}
readDir(directoryPath);