Skip to content

Commit 94dced2

Browse files
author
fabianmoronzirfas
committed
feat(index): sorted by cats and sub cats
added some style as well
1 parent 7117270 commit 94dced2

18 files changed

+6882
-115
lines changed

.bin/explore.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
const data = require('../_data/cats-and-subcats.json');
2+
console.log(data);

.bin/files-and-folders.js

Lines changed: 49 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -10,27 +10,55 @@ const YAML = require('yamljs');
1010
const data = require('../_data/categories.json'); // load the cats
1111
const OVERWRITE = true; // if we want to recreate everyting
1212
// 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,
21-
codetitle: e.codetitle,
22-
description: e.description,
23-
category: e.category,
24-
subcategory: e.subcategory,
25-
returns: e.returns,
26-
parameters: e.parameters,
27-
kind: e.kind
28-
}, 2);
29-
fs.outputFile(file, `---\n${frontmatter}\n---\n`, (error)=>{
30-
if(error) {
31-
console.log(error);
32-
}
33-
});
13+
14+
function process(ele, folder) {
15+
ele.entries.forEach((e, i, arr)=>{
16+
// console.log(e);
17+
let file = `${folder}${e.name}.md`;
18+
let frontmatter = YAML.stringify({
19+
layout: 'entry',
20+
title: e.name,
21+
codetitle: e.codetitle,
22+
description: e.description,
23+
category: e.category,
24+
subcategory: e.subcategory,
25+
returns: e.returns,
26+
parameters: e.parameters,
27+
kind: e.kind
28+
}, 2);
29+
fs.outputFile(file, `---\n${frontmatter}\n---\n`, (error)=>{
30+
if(error) {
31+
console.log(error);
32+
}
3433
});
34+
});
35+
}
36+
37+
data.forEach((element, index, array)=>{
38+
if(element.cat !== 'null') {
39+
process(element, `./${element.cat.toLowerCase()}/`);
40+
// element.entries.forEach((e, i, arr)=>{
41+
// console.log(e);
42+
// let file = `./${element.cat.toLowerCase()}/${e.name}.md`;
43+
// let frontmatter = YAML.stringify({
44+
// layout: 'entry',
45+
// title: e.name,
46+
// codetitle: e.codetitle,
47+
// description: e.description,
48+
// category: e.category,
49+
// subcategory: e.subcategory,
50+
// returns: e.returns,
51+
// parameters: e.parameters,
52+
// kind: e.kind
53+
// }, 2);
54+
// fs.outputFile(file, `---\n${frontmatter}\n---\n`, (error)=>{
55+
// if(error) {
56+
// console.log(error);
57+
// }
58+
// });
59+
// });
60+
}else{
61+
process(element, './global/');
3562
}
63+
3664
});

.bin/json-transform.js

Lines changed: 47 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -113,8 +113,9 @@ api.forEach((e, i, arr)=> {
113113
let filter = new Filters();
114114
data.forEach((element)=>{
115115

116-
console.log(element);
116+
// console.log(element);
117117
element.name = filter.dotNull(element.name);
118+
element.category = filter.nullToGlobal(element.category);
118119
});
119120

120121
data = generator(data);
@@ -138,6 +139,44 @@ let sortedBySubCategory = _.chain(data)
138139
};
139140
}).value();
140141

142+
let catsAndSubcats = [];
143+
sortedByCategory.forEach((ele)=>{
144+
let res = _.chain(ele.entries)
145+
.groupBy('subcategory')
146+
.map((key, val)=>{
147+
return {
148+
entries: key,
149+
subcat: val,
150+
cat: ele.cat
151+
};
152+
}).value();
153+
catsAndSubcats.push(res);
154+
});
155+
156+
catsAndSubcats.forEach((element)=>{
157+
element.forEach((ele)=>{
158+
// console.log(ele);
159+
if(ele.subcat === 'null') {
160+
ele.subcat = '0';
161+
}
162+
});
163+
164+
element.sort((a, b)=>{
165+
let txt1 = a.subcat.toUpperCase();
166+
let txt2 = b.subcat.toUpperCase();
167+
return (txt1 < txt2) ? -1 : (txt1 > txt2) ? 1 : 0;
168+
});
169+
170+
element.forEach((ele)=>{
171+
// console.log(ele);
172+
if(ele.subcat === '0') {
173+
ele.subcat = 'null';
174+
}
175+
});
176+
});
177+
178+
179+
// console.log(JSON.stringify(catsAndSubcats, null, 2));
141180

142181
fs.writeFile('./_data/categories.json', JSON.stringify(sortedByCategory, null, 2), (err)=>{
143182
if(err) {
@@ -150,3 +189,10 @@ fs.writeFile('./_data/sub-categories.json', JSON.stringify(sortedBySubCategory,
150189
throw err;
151190
}
152191
});
192+
193+
fs.writeFile('./_data/cats-and-subcats.json', JSON.stringify(catsAndSubcats, null, 2), (err)=>{
194+
if(err) {
195+
throw err;
196+
}
197+
});
198+

.bin/lib/filters.js

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ function Filters () {
88
}
99
return str;
1010
};
11+
12+
this.nullToGlobal = function(str) {
13+
if(str === null) {
14+
str = 'global';
15+
}
16+
return str;
17+
};
1118
}
1219

1320
module.exports = Filters;

_data/categories.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"name": "b",
66
"description": null,
77
"returns": null,
8-
"category": null,
8+
"category": "global",
99
"subcategory": null,
1010
"parameters": [],
1111
"kind": "class",
@@ -24,7 +24,7 @@
2424
"codetitle": "b"
2525
}
2626
],
27-
"cat": "null"
27+
"cat": "global"
2828
},
2929
{
3030
"entries": [

0 commit comments

Comments
 (0)