Skip to content

Commit

Permalink
Add generate script for json
Browse files Browse the repository at this point in the history
  • Loading branch information
JacksonTian committed Oct 24, 2014
1 parent d2b9f0e commit 6f9f333
Show file tree
Hide file tree
Showing 7 changed files with 3,033 additions and 2,686 deletions.
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
all:
node ./bin/generate.js
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@ Frontend Knowledge Structure

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

尽管会变成文字的方式来维护这些内容,但是我承诺写一个小工具帮大家生成更好玩的图形(基于DataV项目)。

## 前端开发知识结构
- 前端工程师
- 浏览器
Expand Down Expand Up @@ -79,10 +77,10 @@ Frontend Knowledge Structure
- [CommonJS Modules](http://wiki.commonjs.org/wiki/Modules/1.0)/[AMD](https://github.com/amdjs/amdjs-api/wiki/AMD)
- [HTML5](http://www.w3.org/html/wg/drafts/html/master/)/[CSS3](http://www.w3.org/Style/CSS/specs.en.html)
- [Semantic Web](http://semanticweb.org/)
- [MicroData](http://schema.org)
- [MicroData](http://schema.org)
- [RDFa](http://www.w3.org/TR/rdfa-core/)
- [Web Accessibility](http://www.w3.org/TR/WAI-WEBCONTENT/)
- [Role Attribute](http://www.w3.org/TR/role-attribute/)
- [Role Attribute](http://www.w3.org/TR/role-attribute/)
- [WAI-ARIA](http://www.w3.org/TR/wai-aria/)
- 性能
- [JSPerf](http://jsperf.com/)
Expand Down Expand Up @@ -164,6 +162,7 @@ Frontend Knowledge Structure
- SVG: [D3](http://d3js.org/)/[Raphaël](http://raphaeljs.com/)/[Snap.svg](http://snapsvg.io/)/[DataV](http://datavlab.org/datavjs/)
- Canvas: [CreateJS](http://www.createjs.com/)/[KineticJS](http://kineticjs.com/)
- WebGL(http://zh.wikipedia.org/wiki/WebGL):[Three.JS](http://threejs.org/)

- 后端工程师
- 编程语言
- C/C++/Java/PHP/Ruby/Python/...
Expand Down Expand Up @@ -267,7 +266,7 @@ Frontend Knowledge Structure
active : 53 days
commits : 108
files : 4
authors :
authors :
56 Jackson Tian 51.9%
9 吴晓兰 8.3%
5 liyinkan 4.6%
Expand Down
85 changes: 85 additions & 0 deletions bin/generate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
var fs = require('fs');
var path = require('path');

var readme = fs.readFileSync(path.join(__dirname, '../README.md'), 'utf8');

var getItems = function (str) {
var patt = /([ ]*)-(.*)/g;
var result;

var list = [];
while ((result = patt.exec(str)) != null) {
list.push({level: result[1].length / 4, content: result[2].trim()});
}
return list;
};

var filter = function (list) {
var j = 0;
var f2e = [];
for (var i = 0; i < list.length; i++) {
var item = list[i];
if (item.level === 0) {
j = j + 1;
if (j === 2) {
break;
}
}

f2e.push(item);
}
return f2e;
};

var format = function (list) {
var result = [];
for (var i = 0; i < list.length; i++) {
var item = list[i];
var data = {
id: '' + i,
name: item.content,
level: item.level
};
result.push(data);
}
return result;
};

var items = getItems(readme);
var f2e = filter(items);
var formated = format(f2e);

var buildTree = function (list) {
var root = null;
for (var i = 0; i < list.length; i++) {
var item = list[i];
if (root === null) {
root = item;
root.children = [];
}

var lastLevel0 = root.children;
if (item.level === 1) {
delete item.level;
lastLevel0.push(item);
}

if (item.level === 2) {
var lastLevel1 = lastLevel0[lastLevel0.length - 1];
lastLevel1.children = lastLevel1.children || [];
lastLevel1.children.push(item);
}

if (item.level === 3) {
var lastLevel1Child = lastLevel0[lastLevel0.length - 1].children;
var lastLevel2 = lastLevel1Child[lastLevel1Child.length - 1];
lastLevel2.children = lastLevel2.children || [];
lastLevel2.children.push(item);
}
delete item.level;
}
return root;
};

var tree = buildTree(formated);
fs.writeFileSync(path.join(__dirname, '../frontend_knowledge/f2e.json'), JSON.stringify(tree, null, ' '));
Loading

0 comments on commit 6f9f333

Please sign in to comment.