forked from cockroachdb/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsidebar.html
executable file
·138 lines (125 loc) · 5.5 KB
/
sidebar.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
<div class="col-sidebar">
<script src="{{ 'js/initSidebar.js' | relative_url }}"></script>
<ul id="sidebar" class="nav {% if page.name == 'index.md' %}nav--home{% endif %}{% if page.url == '/search.html'%}nav--search{% endif %}" style="display: none">
<div class="sidenav-arrow"><div class="arrow-down"></div></div>
<div class="collapsed-header">
Docs Menu
{% comment %}
On pages that match a sidebar entry, the JavaScript below
injects the following HTML.
<div class="collapsed-header__pre">
Breadcrumb level 1
<div class=\"arrow-down arrow-down--pre\"></div>
Breadcrumb level 2
</div>
<div>Page title</div>
{% endcomment %}
</div>
<li class="search-wrap">
<div class="search">
<span class="fa fa-search"></span>
<form class="search-form" method="GET" action="{{ 'search.html' | relative_url }}">
<input type="text" id="search-input" name="q" placeholder="Search docs">
<span class="clear-search"></span>
</form>
</div>
</li>
<script>
(function () {
var baseUrl = "{{ site.baseurl }}";
var isVersionDirectory = function (d) {
// Version directories either are one of the named version
// aliases specifed in _config.yml or have the form "vX.X",
// like "v1.0" or "v1.10".
return {{ site.versions | jsonify }}[d] || /^v\d+.\d+$/.test(d);
};
// We derive the version from the URL rather than hardcoding
// `page.version` so that the source of pages for "named"
// versions, like stable and edge, can be identical to the
// source for the underlying version, like v1.0 or v1.1.
// Otherwise, the sidebar for a `stable` page would
// inappropriately link to the underlying `v1.0` page instead
// of the `stable` alias.
var pageVersion = (function () {
var pathComponents = location.pathname
.replace(baseUrl, '')
.replace(/^\//, '')
.split('/');
// The version is the first directory component in the URL,
// if it exists.
if (pathComponents.length > 1 && isVersionDirectory(pathComponents[0])) {
return pathComponents[0];
}
// Non-versioned pages link to stable docs.
return "stable";
})();
// Given a sidebar hierarchy (see _data/sidebar-data-v1.0.json
// for an example), returns a jQuery <ul> element with the
// following structure:
//
// <ul>
// <li class="tier-1">
// <a href="{{ item.url }}">{{ item.title }}</a>
// <ul>
// {% for item in item.items %}
// <li class="tier-2">...</li>
// {% endfor %}
// </ul>
// </li>
// </ul>
//
// Additionally injects breadcrumbs for the active sidebar
// entry, if any, into the `.collapsed-header` element above.
function renderItems(items, paths) {
if (!items || items.length == 0)
return $();
var lis = items.map(function (item) {
var urls = (item.urls || []).map(function (url) {
var url = url.replace("${VERSION}", pageVersion);
// This condition makes it possible to use external
// urls in the sidebar.
if (!/^https?:/.test(url)) {
url = baseUrl + url;
}
return url;
});
// this ensures page will be highlighted in sidebar even if URL is accessed without `.html` appended
var activePathname = location.pathname.slice(-5) === '.html' ? location.pathname : location.pathname + '.html';
var active = (urls.indexOf(activePathname) !== -1);
if (active) {
// This mutation inside an otherwise pure function is
// unfortunate, but doing it here avoids a separate
// traversal of the sidebar data.
var breadcrumbs = $("<div>")
.addClass("collapsed-header__pre")
.html(paths.join("<div class=\"arrow-down arrow-down--pre\"></div>\n"));
var title = $("<div>").html(item.title);
$(".collapsed-header").empty().append(breadcrumbs, title);
}
var subitems = renderItems(item.items, paths.concat(item.title));
var a = $("<a>")
.attr("href", urls[0] || "#")
.html(item.title);
if (subitems.length > 0) {
if (item.is_top_level) {
a.append(" ").append($("<div>").addClass("nav-expand"));
} else {
a.append(" ").append($("<div>").addClass("arrow-down"));
}
}
return $("<li>")
.addClass("tier-" + (paths.length + 1))
.toggleClass("active", active)
.append(a)
.append(subitems);
});
return $("<ul>").append(lis);
}
document.write(renderItems({% include {{ page.sidebar_data }} %}, []).html());
})();
</script>
</ul>
<script src="{{ 'js/searchInputRendering.js' | relative_url }}"></script>
</div>
<!-- this highlights the active parent class in the navgoco sidebar. this is critical so that the parent expands when you're viewing a page. This must appear below the sidebar code above.-->
<script>$("#sidebar").find("li.active").parents('li').toggleClass("active");</script>