Skip to content

Commit 5733029

Browse files
author
Manuel Mujica
committed
Use bit-docs-html-toc plugin istead of old content-lists code
1 parent 4443e96 commit 5733029

File tree

6 files changed

+17
-83
lines changed

6 files changed

+17
-83
lines changed

make-example.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,8 @@ generate(docMap, {
1717
dependencies: {
1818
"bit-docs-docjs-theme": __dirname,
1919
"bit-docs-prettify": "^0.1.0",
20-
"bit-docs-html-highlight-line": "^0.2.2"
20+
"bit-docs-html-highlight-line": "^0.2.2",
21+
"bit-docs-html-toc": "^0.2.1"
2122
}
2223
},
2324
dest: path.join(__dirname, "temp"),

package.json

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
},
2121
"homepage": "https://github.com/bit-docs/bit-docs-docjs-theme#readme",
2222
"devDependencies": {
23-
"bit-docs-generate-html": "^0.3.3"
24-
},
25-
"dependencies": {
26-
"jquery": "^3.1.1"
23+
"bit-docs-generate-html": "^0.3.3",
24+
"bit-docs-html-toc": "^0.2.1"
2725
}
2826
}

static/docjs.js

Lines changed: 0 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -1,69 +1 @@
1-
var $ = require("jquery");
2-
31
require("./styles/styles.less");
4-
5-
$(function() {
6-
var sections = [];
7-
var $element = $(".contents");
8-
9-
collectSignatures().each(function(ix) {
10-
var $h2 = $(this).find("h2");
11-
var id = "sig_" + $h2.text().replace(/\s/g, "").replace(/[^\w]/g, "_");
12-
13-
$(this).attr("id", "id");
14-
sections.push({ id: id, text: $h2.text() });
15-
});
16-
17-
collectHeadings().each(function(ix) {
18-
var $el = $(this);
19-
var id = "section_" + $el.text().replace(/\s/g, "").replace(/[^\w]/g, "_");
20-
21-
$el.attr("id", id).prepend(anchorTemplate({ id: id }));
22-
sections.push({ id: id, text: $el.text() });
23-
});
24-
25-
$element.html(contentListTemplate({ sections: sections }));
26-
27-
if (window.location.hash.length) {
28-
var id = window.location.hash.replace("#", "");
29-
var anchor = document.getElementById(id);
30-
31-
if (anchor) anchor.scrollIntoView(true);
32-
}
33-
});
34-
35-
function collectSignatures() {
36-
var cloned = $(".content .signature").clone();
37-
// remove release numbers
38-
cloned.find(".release").remove();
39-
return cloned;
40-
}
41-
42-
function collectHeadings() {
43-
return $(".content .comment h2, .content .comment h3");
44-
}
45-
46-
function anchorTemplate(ctx) {
47-
var id = encodeURIComponent(ctx.id);
48-
49-
return (
50-
'<a class="anchor" href="#' + id + '" aria-hidden="true">' +
51-
'<svg aria-hidden="true" class="octicon octicon-link" height="16" version="1.1" viewBox="0 0 16 16" width="16">' +
52-
'<path d="M4 9h1v1h-1c-1.5 0-3-1.69-3-3.5s1.55-3.5 3-3.5h4c1.45 0 3 1.69 3 3.5 0 1.41-0.91 2.72-2 3.25v-1.16c0.58-0.45 1-1.27 1-2.09 0-1.28-1.02-2.5-2-2.5H4c-0.98 0-2 1.22-2 2.5s1 2.5 2 2.5z m9-3h-1v1h1c1 0 2 1.22 2 2.5s-1.02 2.5-2 2.5H9c-0.98 0-2-1.22-2-2.5 0-0.83 0.42-1.64 1-2.09v-1.16c-1.09 0.53-2 1.84-2 3.25 0 1.81 1.55 3.5 3 3.5h4c1.45 0 3-1.69 3-3.5s-1.5-3.5-3-3.5z"></path>' +
53-
'</svg>' +
54-
'</a>'
55-
);
56-
}
57-
58-
function contentListTemplate(ctx) {
59-
var sections = ctx.sections || [];
60-
61-
var items = sections.map(function(section) {
62-
var text = section.text;
63-
var id = encodeURIComponent(section.id);
64-
65-
return '<li><a href="#' + id + '">' + text + '</a></li>';
66-
});
67-
68-
return '<ul>' + items.join('') + '</li>';
69-
}

templates/content.mustache

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -13,22 +13,23 @@
1313
{{> menu.mustache}}
1414
</nav>
1515
{{/unless}}
16-
16+
1717
{{#unless hideArticle}}
1818
<article class="content docs">
1919
{{/unless}}
20-
20+
2121
{{#unless hideTitle}}
2222
<section class="title">
2323
{{> title.mustache}}
2424
</section>
2525
{{/unless}}
26-
26+
2727
{{#unless hideArticle}}
2828
<section class="contents">
29+
<div class="on-this-page-container"></div>
2930
</section>
3031
{{/unless}}
31-
32+
3233
{{#if deprecated.length}}
3334
<section class='warnings'>
3435
{{#deprecated}}
@@ -61,13 +62,13 @@
6162
</section>
6263
{{/if}}
6364
{{/if}}
64-
65+
6566
{{#ifAny params returns}}
6667
<section class="signature">
6768
{{> signature.mustache}}
6869
</section>
6970
{{/ifAny}}
70-
71+
7172

7273
{{#if body}}
7374
<section class="comment">
@@ -83,7 +84,7 @@
8384
<section class="comment">
8485
<h2>{{title}}</h2>
8586
</section>
86-
87+
8788
{{#if description}}
8889
<section class="description">
8990
{{{chain "makeHtml" "makeLinks" description}}}
@@ -106,11 +107,11 @@
106107
{{{makeApiSection}}}
107108
</section>
108109
{{/if}}
109-
110+
110111
{{#unless hideArticle}}
111112
</article>
112113
{{/unless}}
113-
114+
114115
{{#unless hideContainer}}
115116
</div>
116117
{{/unless}}

templates/layout.mustache

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
<body class="docs">
3333
{{#unless hideHeader}}
3434
<header>
35+
{{! workaround for https://github.com/bit-docs/bit-docs-html-toc/issues/2 }}
36+
<div style="display: none;" class="navbar"></div>
3537
<nav class="container">
3638
<div class="logo-menu">
3739
<a class="brand" href="./index.html">{{makeParentTitle}}</a>

templates/title.mustache

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{{/if}}
1515
{{/if}}
1616
{{#if types}}
17-
<h2><code>{{{makeTypesString types}}}</code></h2>
17+
<code>{{{makeTypesString types}}}</code>
1818
{{/if}}
1919
<span class="inherits">{{#if inherits}}inherits: <a href="{{urlTo inherits}}">{{inherits}}</a>{{else}}&nbsp;{{/if}}</span>
2020
</div>

0 commit comments

Comments
 (0)