Skip to content

Commit 14ca7b7

Browse files
author
fabianmoronzirfas
committed
added data transfor scripts
1 parent b897c42 commit 14ca7b7

File tree

5 files changed

+106
-0
lines changed

5 files changed

+106
-0
lines changed

.bin/.DS_Store

6 KB
Binary file not shown.

.bin/Notes.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Notes
2+
3+
Generating JSON in jekyll
4+
5+
https://www.youtube.com/watch?v=XTAFSDqQMko
6+
7+
Search using lunr.js
8+
9+
http://jekyll.tips/jekyll-casts/jekyll-search-using-lunr-js/
10+
11+
http://matthewdaly.co.uk/blog/2015/04/18/how-i-added-search-to-my-site-with-lunr-dot-js/

.bin/json-transform.js

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
const fs = require('fs');
2+
const api = require('../_data/api.json');
3+
const Entry = require('./lib/entry');
4+
const Parameter = require('./lib/parameter');
5+
6+
let data = [];
7+
8+
api.forEach((e, i, arr)=> {
9+
let entry = new Entry();
10+
// console.log(`\n# Title:\n${e.name}`);
11+
entry.name = e.name;
12+
// //console.log(`# ${JSON.stringify(e.description)}`);
13+
if(e.description instanceof Object) {
14+
let des = e.description.children[0].children[0].value;
15+
// console.log(`## Description:\n${des}`);
16+
entry.description = des;
17+
}
18+
19+
if(Array.isArray(e.params)) {
20+
// console.log('\n### Parameters:');
21+
e.params.forEach((ele, ndx, array)=> {
22+
let param = new Parameter();
23+
param.name = ele.name;
24+
let descr = (ele.description instanceof Object) ? ele.description.children[0].children[0].value : '';
25+
param.description = descr;
26+
entry.parameters.push(param);
27+
// console.log(`Argument ${ndx + 1}\nName: ${ele.name}\nDescription:\n ${descr}`);
28+
});
29+
}
30+
if(Array.isArray(e.returns)) {
31+
// console.log('### Returns');
32+
if(e.returns[0].description.children.length > 0) {
33+
let ret = e.returns[0].description.children[0].children[0].value;
34+
entry.returns = ret;
35+
// console.log(ret);
36+
37+
}
38+
}
39+
if(Array.isArray(e.tags)) {
40+
e.tags.forEach((ele, ndx, array)=>{
41+
if(ele.title === 'cat') {
42+
// //console.log(ele.title);
43+
// console.log(`\n### Category:\n${ele.description}`);
44+
entry.category = ele.description;
45+
}
46+
if(ele.title === 'subcat') {
47+
// //console.log(ele.title);
48+
// console.log(`\n### Sub Category:\n${ele.description}`);
49+
entry.subcategory = ele.description;
50+
}
51+
// let tag = _.find(ele, 'title');
52+
// //console.log(tag);
53+
// let tag = _.find(ele, (o)=>{
54+
// return o.title === 'cat';
55+
// });
56+
// //console.log(tag.description);
57+
});
58+
}
59+
// for(let k in e) {
60+
// if(e.hasOwnProperty(k)) {
61+
// //console.log(`\t${k}`);
62+
// }
63+
// }
64+
data.push(entry);
65+
// console.log('-----------------\n');
66+
});
67+
68+
// console.log(JSON.stringify(data, null, 2));
69+
70+
fs.writeFile('./_data/data.json', JSON.stringify(data), (err)=>{
71+
if(err) {
72+
throw err;
73+
}
74+
// //console.log('saved');
75+
});

.bin/lib/entry.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
var exports = module.exports = {};
2+
3+
function Entry() {
4+
this.name = null;
5+
this.description = null;
6+
this.returns = null;
7+
this.category = null;
8+
this.subcategory = null;
9+
this.parameters = [];
10+
}
11+
12+
module.exports = Entry;

.bin/lib/parameter.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
var exports = module.exports = {};
2+
3+
function Paramter() {
4+
this.name = null;
5+
this.description = null;
6+
}
7+
8+
module.exports = Paramter;

0 commit comments

Comments
 (0)