Skip to content

Commit 6f9f333

Browse files
committed
Add generate script for json
1 parent d2b9f0e commit 6f9f333

File tree

7 files changed

+3033
-2686
lines changed

7 files changed

+3033
-2686
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
all:
2+
node ./bin/generate.js

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,6 @@ Frontend Knowledge Structure
77

88
图片的形式具有诸多的不便。缺失源图的我们,无法为此图贡献些什么,随着时间的迁移,或许有些技术点会发生改变,所以有了这个GitHub项目。我们可以通过协作的方式来共同维护这个项目。Git的历史记录也可以见证前端行业的一些变迁。
99

10-
尽管会变成文字的方式来维护这些内容,但是我承诺写一个小工具帮大家生成更好玩的图形(基于DataV项目)。
11-
1210
## 前端开发知识结构
1311
- 前端工程师
1412
- 浏览器
@@ -79,10 +77,10 @@ Frontend Knowledge Structure
7977
- [CommonJS Modules](http://wiki.commonjs.org/wiki/Modules/1.0)/[AMD](https://github.com/amdjs/amdjs-api/wiki/AMD)
8078
- [HTML5](http://www.w3.org/html/wg/drafts/html/master/)/[CSS3](http://www.w3.org/Style/CSS/specs.en.html)
8179
- [Semantic Web](http://semanticweb.org/)
82-
- [MicroData](http://schema.org)
80+
- [MicroData](http://schema.org)
8381
- [RDFa](http://www.w3.org/TR/rdfa-core/)
8482
- [Web Accessibility](http://www.w3.org/TR/WAI-WEBCONTENT/)
85-
- [Role Attribute](http://www.w3.org/TR/role-attribute/)
83+
- [Role Attribute](http://www.w3.org/TR/role-attribute/)
8684
- [WAI-ARIA](http://www.w3.org/TR/wai-aria/)
8785
- 性能
8886
- [JSPerf](http://jsperf.com/)
@@ -164,6 +162,7 @@ Frontend Knowledge Structure
164162
- SVG: [D3](http://d3js.org/)/[Raphaël](http://raphaeljs.com/)/[Snap.svg](http://snapsvg.io/)/[DataV](http://datavlab.org/datavjs/)
165163
- Canvas: [CreateJS](http://www.createjs.com/)/[KineticJS](http://kineticjs.com/)
166164
- WebGL(http://zh.wikipedia.org/wiki/WebGL):[Three.JS](http://threejs.org/)
165+
167166
- 后端工程师
168167
- 编程语言
169168
- C/C++/Java/PHP/Ruby/Python/...
@@ -267,7 +266,7 @@ Frontend Knowledge Structure
267266
active : 53 days
268267
commits : 108
269268
files : 4
270-
authors :
269+
authors :
271270
56 Jackson Tian 51.9%
272271
9 吴晓兰 8.3%
273272
5 liyinkan 4.6%

bin/generate.js

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,85 @@
1+
var fs = require('fs');
2+
var path = require('path');
3+
4+
var readme = fs.readFileSync(path.join(__dirname, '../README.md'), 'utf8');
5+
6+
var getItems = function (str) {
7+
var patt = /([ ]*)-(.*)/g;
8+
var result;
9+
10+
var list = [];
11+
while ((result = patt.exec(str)) != null) {
12+
list.push({level: result[1].length / 4, content: result[2].trim()});
13+
}
14+
return list;
15+
};
16+
17+
var filter = function (list) {
18+
var j = 0;
19+
var f2e = [];
20+
for (var i = 0; i < list.length; i++) {
21+
var item = list[i];
22+
if (item.level === 0) {
23+
j = j + 1;
24+
if (j === 2) {
25+
break;
26+
}
27+
}
28+
29+
f2e.push(item);
30+
}
31+
return f2e;
32+
};
33+
34+
var format = function (list) {
35+
var result = [];
36+
for (var i = 0; i < list.length; i++) {
37+
var item = list[i];
38+
var data = {
39+
id: '' + i,
40+
name: item.content,
41+
level: item.level
42+
};
43+
result.push(data);
44+
}
45+
return result;
46+
};
47+
48+
var items = getItems(readme);
49+
var f2e = filter(items);
50+
var formated = format(f2e);
51+
52+
var buildTree = function (list) {
53+
var root = null;
54+
for (var i = 0; i < list.length; i++) {
55+
var item = list[i];
56+
if (root === null) {
57+
root = item;
58+
root.children = [];
59+
}
60+
61+
var lastLevel0 = root.children;
62+
if (item.level === 1) {
63+
delete item.level;
64+
lastLevel0.push(item);
65+
}
66+
67+
if (item.level === 2) {
68+
var lastLevel1 = lastLevel0[lastLevel0.length - 1];
69+
lastLevel1.children = lastLevel1.children || [];
70+
lastLevel1.children.push(item);
71+
}
72+
73+
if (item.level === 3) {
74+
var lastLevel1Child = lastLevel0[lastLevel0.length - 1].children;
75+
var lastLevel2 = lastLevel1Child[lastLevel1Child.length - 1];
76+
lastLevel2.children = lastLevel2.children || [];
77+
lastLevel2.children.push(item);
78+
}
79+
delete item.level;
80+
}
81+
return root;
82+
};
83+
84+
var tree = buildTree(formated);
85+
fs.writeFileSync(path.join(__dirname, '../frontend_knowledge/f2e.json'), JSON.stringify(tree, null, ' '));

0 commit comments

Comments
 (0)