8000 Add search functionality to docs (#137) · irislips/server-client-python@b6f3dae · GitHub
[go: up one dir, main page]

Skip to content

Commit b6f3dae

Browse files
jdomingut8y8
authored andcommitted
Add search functionality to docs (tableau#137)
1 parent dc9c0eb commit b6f3dae

File tree

9 files changed

+148
-0
lines changed

9 files changed

+148
-0
lines changed

docs/_includes/docs_menu.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
<div class="well docs-menu col-xs-12 col-sm-4 col-md-3">
2+
{% include search_form.html %}
23
<ul class="nav nav-list">
34
<li>
45
<a href="{{ site.baseurl }}/docs">Get Started</a>

docs/_includes/head.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
<link rel="stylesheet" href="{{ site.baseurl }}/css/main.css">
1212
<link rel="stylesheet" href="{{ site.baseurl }}/css/github-highlight.css">
1313

14+
<script src="{{ site.baseurl }}/js/redirect-to-search.js"></script>
1415
<script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
1516
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.6/js/bootstrap.min.js"></script>
1617

docs/_includes/search_form.html

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<div class="search-container form-group has-feedback">
2+
<form id="docs-search">
3+
<input type="search" id="search-input" class="custom-search form-control" placeholder="Search the docs..." search-url="{{ site.baseurl}}/docs/search.html">
4+
<span class="glyphicon glyphicon-search form-control-feedback"></span>
5+
</form>
6+
</div>
7+

docs/_layouts/search.html

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
---
2+
layout: search
3+
---
4+
5+
<!DOCTYPE html>
6+
<html>
7+
8+
<head>
9+
{% include head.html %}
10+
<script type="text/javascript">
11+
var search_blob = {
12+
{% for page in site.pages %}
13+
{% if page.indexed_by_search != false %}
14+
"{{ site.baseurl }}{{ page.url }}": {
15+
"title": {{ page.title | escape | jsonify }},
16+
"content": {{ page.content | remove_first: '* TOC' | replace_first:':toc',':class="blank"' | markdownify | strip_html | normalize_whitespace | jsonify }}
17+
}{% unless forloop.last %},{% endunless %}
18+
{% endif %}
19+
{% endfor %}
20+
};
21+
</script>
22+
23+
<script src="{{ site.baseurl }}/js/lunr.min.js"></script>
24+
<script src="{{ site.baseurl }}/js/search.js"></script>
25+
</head>
26+
27+
<body>
28+
<div class="container">
29+
{% include header.html %}
30+
{% include docs_menu.html %}
31+
32+
<div class="content .col-xs-12 .col-sm-8 .col-md-9">
33+
<h1 id="searchHeading"></h1>
34+
<br />
35+
<div id="searchResultsContainer">
36+
<p>Loading search results...</p>
37+
</div>
38+
39+
{% include footer.html %}
40+
</div>
41+
</div>
42+
</body>
43+
</html>

docs/docs/search.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
title: Search
3+
layout: search
4+
---
5+

docs/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
---
22
layout: home
3+
indexed_by_search: false
34
---
45

56
<header class="jumbotron hero-spacer text-center">

docs/js/lunr.min.js

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/js/redirect-to-search.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
(function () {
2+
window.addEventListener('load', function () {
3+
var search_form = document.getElementById('docs-search');
4+
var search_input = document.getElementById('search-input');
5+
6+
if (search_form) {
7+
search_form.addEventListener('submit', function (e) {
8+
e.preventDefault();
9+
window.location.href = search_input.getAttribute('search-url') + '?q=' + encodeURIComponent(search_input.value);
10+
});
11+
}
12+
});
13+
})();

0 commit comments

Comments
 (0)
0