Skip to content

Commit 85f9535

Browse files
committed
添加data.json
1 parent f5101ad commit 85f9535

File tree

3 files changed

+34
-10
lines changed

3 files changed

+34
-10
lines changed

build/compile.js

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -240,30 +240,49 @@ function CreateStyl(styl_path,css_path){
240240
function CreateDatajs(dt_path,callback){
241241
// 获取 markdown文件所在的目录
242242
var path_md = path.join(path.dirname(__dirname),'command');
243+
var path_dist = path.join(path.dirname(__dirname),'dist');
243244
if(!exists(path_md)) return console.log("\n → error: 文件夹 "+path_md+" 不存在 \n ")
244245
// 获取 markdown 目录的集合
245246
var path_arr = readMDSync(path_md);
246247
path_arr = sortLength(path_arr);
247-
var indexes = []
248+
var indexes = [];
249+
250+
var command_data={}
248251
path_arr.forEach(function(md_path,i){
249252
var json = {}
250253
var con = fs.readFileSync(md_path);
251254
var str = con.toString();
252255
var title = str.match(/[^===]+(?=[===])/g);
256+
257+
title = title[0]?title[0].replace(/\n/g,''):title[0];
253258
// 命令名称
254-
json["n"] = title[0]?title[0].replace(/\n/g,''):title[0];
259+
json["n"] = title;
255260
// 命令路径
256261
json["p"] = md_path.replace(/\.md$/,'').replace(path_md,'');
257262
// 命令描述
258263
var des = str.match(/\n==={1,}([\s\S]*?)##/i);
259-
json["d"] = des[1]?des[1].replace(/\n/g,''):des[1];
264+
des = des[1]?des[1].replace(/\n/g,''):des[1];
265+
des = des.replace(/\r/g,'')
266+
json["d"] = des;
260267
indexes.push(json)
268+
269+
command_data[title] = json;
261270
})
262271
mkdirsSync(path.dirname(dt_path));
272+
273+
console.log("path.dirname(__dirname)",path.dirname(__dirname))
263274
//生成数据文件
264275
fs.writeFile(dt_path, 'var linux_commands='+JSON.stringify(indexes) , 'utf8',function(err){
265276
console.log(success("\n → ")+"生成数据成功!"+dt_path+" \n ");
266-
callback&&callback(dt_path,indexes);
277+
278+
279+
path_dist = path.join(path_dist,'data.json')
280+
281+
fs.writeFile(path_dist, JSON.stringify(command_data) , 'utf8',function(err){
282+
console.log(success("\n → ")+"生成数据成功!"+path_dist+" \n ");
283+
callback&&callback(dt_path,indexes);
284+
});
285+
267286
});
268287
}
269288

dist/data.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "linux-command",
33
"version": "1.0.0",
44
"description": "Linux Command",
5-
"main": "build/compile.js",
5+
"main": "dist/data.js",
66
"scripts": {
77
"test": "echo \"Error: no test specified\" && exit 1",
88
"start": "node build/compile.js",
@@ -18,7 +18,7 @@
1818
"license": "MIT",
1919
"repository": {
2020
"type": "git",
21-
"url": "https://github.com/jaywcjlove/linux-command.git"
21+
"url": "git+https://github.com/jaywcjlove/linux-command.git"
2222
},
2323
"devDependencies": {
2424
"autoprefixer": "^6.5.1",
@@ -29,14 +29,18 @@
2929
"marked": "^0.3.6",
3030
"ssr": "^1.1.1",
3131
"stylus": "^0.54.5",
32-
"watch": "^1.0.1"
33-
},
34-
"dependencies": {
32+
"watch": "^1.0.1",
3533
"cheerio": "^0.22.0",
3634
"gh-pages": "^0.12.0",
3735
"loading-cli": "^1.0.2",
3836
"superagent": "^3.0.0",
3937
"to-markdown": "^3.0.3",
4038
"uglify-js": "^2.7.4"
41-
}
39+
},
40+
"dependencies": {
41+
},
42+
"bugs": {
43+
"url": "https://github.com/jaywcjlove/linux-command/issues"
44+
},
45+
"homepage": "https://jaywcjlove.github.io/linux-command/"
4246
}

0 commit comments

Comments
 (0)