Skip to content

Commit 16b7661

Browse files
authored
Merge pull request #20 from bit-docs/sidebar
Add fields required by the new CanJS sidebar
2 parents abb46b1 + 9fdacef commit 16b7661

File tree

4 files changed

+42
-29
lines changed

4 files changed

+42
-29
lines changed

generators/search-map.js

Lines changed: 23 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,33 +24,32 @@ module.exports = function(docMap, siteConfig) {
2424
var searchMap = {};
2525
var name;
2626
for (name in docMap) {
27-
if (docMap.hasOwnProperty(name)) {
28-
var docObj = docMap[name];
29-
var description = docObj.description && docObj.description.trim();
30-
var signaturesHaveContent = docObj.signatures && docObj.signatures.some(function(signature){
31-
return signature.params || signature.return || signature.options;
32-
});
33-
// If there is no body, it's likely we don't want to index it
34-
if ((description && description !== 'undefined') || signaturesHaveContent) {
35-
var helpers = bitDocsHelpers(docMap, siteConfig, function(){
36-
return docObj;
37-
}, {});
27+
var docObj = (docMap.hasOwnProperty(name)) ? docMap[name] : null;
28+
if (docObj && !docObj.hide) {
29+
30+
var helpers = bitDocsHelpers(docMap, siteConfig, function(){
31+
return docObj;
32+
}, {});
3833

39-
// Convert bit-docs markdown to HTML
40-
var descriptionAsHTML = helpers.makeLinks(helpers.makeHtml(description));
34+
// Convert bit-docs markdown to HTML
35+
var description = docObj.description && docObj.description.trim();
36+
var descriptionAsHTML = helpers.makeLinks(helpers.makeHtml(description));
4137

42-
// Only allow certain HTML elements
43-
var descriptionAsStrippedHTML = striptags(descriptionAsHTML, ['a', 'code', 'em', 'strong']);
38+
// Only allow certain HTML elements
39+
var descriptionAsStrippedHTML = striptags(descriptionAsHTML, ['a', 'code', 'em', 'strong']);
4440

45-
var searchObj = {
46-
name: docObj.name,
47-
title: docObj.title,
48-
description: descriptionAsStrippedHTML,
49-
url: filename(docObj, siteConfig),
50-
dest: 'doc/'
51-
};
52-
searchMap[name] = searchObj;
53-
}
41+
var searchObj = {
42+
collection: docObj.collection || undefined,
43+
description: descriptionAsStrippedHTML || undefined,
44+
name: docObj.name || undefined,
45+
order: docObj.order,
46+
parent: docObj.parent || undefined,
47+
subchildren: docObj.subchildren || undefined,
48+
title: docObj.title || undefined,
49+
type: docObj.type || undefined,
50+
url: filename(docObj, siteConfig) || undefined
51+
};
52+
searchMap[name] = searchObj;
5453
}
5554
}
5655

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "bit-docs-generate-searchmap",
3-
"version": "0.1.7",
3+
"version": "0.2.0-pre.3",
44
"description": "Generates a searchmap from the docMap",
55
"main": "index.js",
66
"scripts": {

test.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,14 @@ describe("bitDocs.generators.searchMap",function(){
4242
});
4343
});
4444

45+
it("(bitDocs.generators.searchMap.searchMap) Excludes docObjects with @hide", function(){
46+
return docMapPromise.then(function(docMap){
47+
return searchMap(docMap, siteConfig).then(function(searchMapResult){
48+
assert.ok(!searchMapResult['guides/what-is-canjs']);
49+
});
50+
});
51+
});
52+
4553
it("(bitDocs.generators.searchMap.searchMap) Strips HTML from the description", function(){
4654
return docMapPromise.then(function(docMap){
4755
return searchMap(docMap, siteConfig);
@@ -60,18 +68,18 @@ describe("bitDocs.generators.searchMap",function(){
6068
});
6169
});
6270

63-
it("(bitDocs.generators.searchMap.searchMap) Filters hidden and empty docObjects", function(){
71+
it("(bitDocs.generators.searchMap.searchMap) Does not filter hidden and empty docObjects", function(){
6472
return docMapPromise.then(function(docMap){
6573
return searchMap(docMap, siteConfig).then(function(searchMapResult){
66-
assert.ok(!searchMapResult.Component);
74+
assert.ok(searchMapResult.Component);
6775
});
6876
});
6977
});
7078

71-
it("(bitDocs.generators.searchMap.searchMap) Filters docObjects with only “undefined\n” as their description", function(){
79+
it("(bitDocs.generators.searchMap.searchMap) Does not filter docObjects with only “undefined\n” as their description", function(){
7280
return docMapPromise.then(function(docMap){
7381
return searchMap(docMap, siteConfig).then(function(searchMapResult){
74-
assert.ok(!searchMapResult['can.Control']);
82+
assert.ok(searchMapResult['can.Control']);
7583
});
7684
});
7785
});

testDocMap.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,5 +178,11 @@
178178
"description": "undefined\n",
179179
"url": "can.Control.html",
180180
"dest": "doc/"
181+
},
182+
"guides/what-is-canjs": {
183+
"description": "\n",
184+
"name": "guides/what-is-canjs",
185+
"title": "What is CanJS?",
186+
"hide": true
181187
}
182188
}

0 commit comments

Comments
 (0)