Skip to content

Commit fe28052

Browse files
author
fabianmoronzirfas
committed
feat(files): generate all files from categories
1 parent 7d78c7a commit fe28052

File tree

236 files changed

+13366
-6
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

236 files changed

+13366
-6
lines changed

.bin/Notes.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,8 @@ Search using lunr.js
88

99
http://jekyll.tips/jekyll-casts/jekyll-search-using-lunr-js/
1010

11-
http://matthewdaly.co.uk/blog/2015/04/18/how-i-added-search-to-my-site-with-lunr-dot-js/
11+
http://matthewdaly.co.uk/blog/2015/04/18/how-i-added-search-to-my-site-with-lunr-dot-js/
12+
13+
Split by categories
14+
15+
http://stackoverflow.com/questions/14696326/break-array-of-objects-into-separate-arrays-based-on-a-property

.bin/files-and-folders.js

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// should take the data.json
2+
// and go through all the categories
3+
// creates
4+
// - a folder per category
5+
// - a file for each function/variable
6+
// only if they don't exist already
7+
// or a overwrite flag is set
8+
const fs = require('fs-extra');
9+
const YAML = require('yamljs');
10+
const data = require('../_data/categories.json'); // load the cats
11+
const OVERWRITE = true; // if we want to recreate everyting
12+
// console.log(process.cwd());
13+
data.forEach((element, index, array)=>{
14+
if(element.cat !== null && element.cat !== 'null') {
15+
element.entries.forEach((e, i, arr)=>{
16+
console.log(e);
17+
let file = `./${element.cat.toLowerCase()}/${e.name}.md`;
18+
let frontmatter = YAML.stringify({
19+
layout: 'entry',
20+
title: e.name + (e.kind === 'function' ? '()' : ''),
21+
description: e.description,
22+
category: e.category,
23+
subcategory: e.subcategory,
24+
returns: e.returns,
25+
parameters: e.parameters
26+
}, 2);
27+
fs.outputFile(file, `---\n${frontmatter}\n---\n${e.description}`, (error)=>{
28+
if(error) {
29+
console.log(error);
30+
}
31+
});
32+
});
33+
// test if the folder exists
34+
// try{
35+
// fs.accessSync(dir);
36+
// console.log(`folder ${dir} exists`);
37+
// }catch(error) {
38+
// if (error && error.code === 'ENOENT') {
39+
// console.log(`folder '${dir}' does not exist`);
40+
// try{
41+
42+
// fs.mkdirSync(dir);
43+
// }catch(e)
44+
// }
45+
46+
// }
47+
}
48+
});

.bin/json-transform.js

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@ const fs = require('fs');
22
const api = require('../_data/api.json');
33
const Entry = require('./lib/entry');
44
const Parameter = require('./lib/parameter');
5+
const Category = require('./lib/category');
6+
const _ = require('lodash');
7+
58

69
let data = [];
710

@@ -15,6 +18,9 @@ api.forEach((e, i, arr)=> {
1518
// console.log(`## Description:\n${des}`);
1619
entry.description = des;
1720
}
21+
if(e.hasOwnProperty('kind') === true) {
22+
entry.kind = e.kind;
23+
}
1824

1925
if(Array.isArray(e.params)) {
2026
// console.log('\n### Parameters:');
@@ -66,8 +72,38 @@ api.forEach((e, i, arr)=> {
6672
});
6773

6874
// console.log(JSON.stringify(data, null, 2));
75+
// taken from here
76+
// http://stackoverflow.com/questions/23600897/using-lodash-groupby-how-to-add-your-own-keys-for-grouped-output
77+
let sortedByCategory = _.chain(data)
78+
.groupBy('category')
79+
.map((key, val)=>{
80+
return {
81+
entries: key,
82+
cat: val
83+
};
84+
}).value();
85+
86+
let sortedBySubCategory = _.chain(data)
87+
.groupBy('subcategory')
88+
.map((key, val)=>{
89+
return {
90+
entries: key,
91+
subcat: val
92+
};
93+
}).value();
94+
95+
96+
// console.log(JSON.stringify(sortedBySubCategory, null, 2));
97+
98+
99+
fs.writeFile('./_data/categories.json', JSON.stringify(sortedByCategory, null, 2), (err)=>{
100+
if(err) {
101+
throw err;
102+
}
103+
// //console.log('saved');
104+
});
69105

70-
fs.writeFile('./_data/data.json', JSON.stringify(data), (err)=>{
106+
fs.writeFile('./_data/sub-categories.json', JSON.stringify(sortedBySubCategory, null, 2), (err)=>{
71107
if(err) {
72108
throw err;
73109
}

.bin/lib/category.js

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

.bin/lib/entry.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ function Entry() {
77
this.category = null;
88
this.subcategory = null;
99
this.parameters = [];
10+
this.kind = null;
1011
}
1112

1213
module.exports = Entry;

0 commit comments

Comments
 (0)