forked from kitian616/jekyll-TeXt-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathassert-url.js
36 lines (30 loc) · 995 Bytes
/
assert-url.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
#!/usr/bin/env node
var path = require('path');
var fs = require('fs');
var imgRg = /!\[([^\]]*)\]\((\/[^/]\S*)\)/gm;
var basePath = 'https://raw.githubusercontent.com/kitian616/jekyll-TeXt-theme/master';
var srcPaths = ['./test/_posts', './docs/en', './docs/zh'];
function runner() {
srcPaths.forEach(function(srcPath) {
fs.readdir(srcPath, function(err, files) {
files.forEach(function(file) {
var curPath = srcPath + '/' + file;
fs.stat(curPath, function(err, stat) {
if (stat.isFile() && path.extname(curPath) === '.md') {
fs.readFile(curPath, 'utf8', function(err, data) {
if (err) throw err;
data = assertUrl(data);
fs.writeFile(curPath, data, 'utf8', function(err) {
if (err) throw err;
});
});
}
});
});
});
});
}
function assertUrl(content) {
return content.replace(imgRg, '![$1](' + basePath + '$2)');
}
runner();