-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathfix-note.js
68 lines (61 loc) · 1.75 KB
/
fix-note.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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
const fs = require("fs");
const path = require("path");
function travel(dir, callback) {
if (dir.includes("node_modules")) {
return;
}
if (fs.statSync(dir).isFile()) {
if (dir.endsWith(".md")) {
callback(dir);
}
} else {
fs.readdirSync(dir).forEach((file) => {
var pathname = path.join(dir, file);
if (fs.statSync(pathname).isDirectory()) {
travel(pathname, callback);
} else if (pathname.endsWith(".md")) {
callback(pathname);
}
});
}
}
function fix(mdpath) {
let data = fs.readFileSync(mdpath, "utf8");
let updateData = fs.readFileSync(mdpath, "utf8");
let reg = /([ ]*)> \*+Note.*\n(([ ]*>\s*.*\n)*)/g;
while ((m = reg.exec(data))) {
updateData = updateData.replace(
m[0],
m[1] +
'{% callout title="Note" type="note" %}\n' +
m[2].replace(/>[ \n]/g, "") +
m[1] +
"{% /callout %}\n"
);
}
reg = /([ ]*)> \*+Tip.*\n(([ ]*>\s*.*\n)*)/g;
while ((m = reg.exec(data))) {
updateData = updateData.replace(
m[0],
m[1] +
'{% callout title="Tip" type="tip" %}\n' +
m[2].replace(/>[ \n]/g, "") +
m[1] +
"{% /callout %}\n"
);
}
fs.writeFileSync(mdpath, updateData);
console.log(mdpath + " fixed");
}
// Example: node fix-tab.js connectors/aws-lambda-sink/2.10.0/aws-lambda-sink.md
const [dir] = process.argv.slice(2);
travel(path.join(__dirname, dir), fix);
// Usage:
// Example 1: Update a specify md file:
// node fix-tab.js connectors/aws-lambda-sink/2.10.0/aws-lambda-sink.md
// Example 2: Update files in a specify directory:
// node fix-tab.js connectors/aws-lambda-sink
// Example 3: Update all connectors docs:
// node fix-tab.js connectors
// Example 4: Update all docs:
// node fix-tab.js .