Skip to content

Commit 735c334

Browse files
committed
feat: adding in search
1 parent fd7df8e commit 735c334

File tree

4 files changed

+35
-31
lines changed

4 files changed

+35
-31
lines changed

layouts/_default/baseof.html

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,16 @@
77
<meta name="description" content="JS Bin help documentation, tips, tricks, features and blog">
88
<link rel="icon" href="/images/favicon.png">
99
<link href="https://fonts.googleapis.com/css?family=Open+Sans:700,400" rel="stylesheet" type="text/css">
10+
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.css" />
1011
<link rel="stylesheet" href="/css/help.css">{{ "<!--[if lt IE 9]>" | safeHTML }}
11-
<script src="/js/html5shiv.min.js"></script>
12-
{{ "<![endif]-->" | safeHTML }}
13-
</head>
14-
<body data-url="{{ $.GitInfo }}" id="{{ $.URL | replaceRE `/(.*)/` "$1" | replaceRE `/` "-" }}-page">
15-
<div id="container">
16-
<header>
17-
<div class="inner"><a id="back" href="/"><span class="morewords">Back to JS Bin</span></a>
18-
<nav>
12+
<script src="/js/html5shiv.min.js"></script>
13+
{{ "<![endif]-->" | safeHTML }}
14+
</head>
15+
<body data-url="{{ $.GitInfo }}" id="{{ $.URL | replaceRE `/(.*)/` "$1" | replaceRE `/` "-" }}-page">
16+
<div id="container">
17+
<header>
18+
<div class="inner"><a id="back" href="/"><span class="morewords">Back to JS Bin</span></a>
19+
<nav>
1920
<input id="search" placeholder="Search..." spellcheck="false" autocapitalize="off" autocorrect="off">
2021
<ol id="results" hidden></ol>
2122
<a {{if eq $.Section "blog" }}class="selected"{{ end }} href="/blog">Blog</a>
@@ -59,9 +60,23 @@
5960
s.parentNode.insertBefore(wf, s);
6061
})();
6162
</script>
62-
<script src="/js/min.js"></script>
63+
<script type="text/javascript" src="https://cdn.jsdelivr.net/npm/docsearch.js@2/dist/cdn/docsearch.min.js"></script>
64+
<script>
65+
docsearch({
66+
appId: 'X7U969ZCKA',
67+
apiKey: '43c4a4be12146a98c44795c6078dd9d6', // use a SEARCH-ONLY api key here
68+
indexName: 'learn-jsbin',
69+
inputSelector: '#search',
70+
handleSelected: function (input, event, suggestion) {
71+
console.log(input, event, suggestion);
72+
},
73+
74+
debug: false // set to `true` if you want to inspect the dropdown menu's CSS
75+
});
76+
</script>
77+
6378
<script src="/js/permalink.js"></script>
64-
<script src="/js/search.js"></script>
79+
<script type="foo" src="/js/search.js"></script>
6580
<script src="/js/xhr.js"></script>
6681
<script src="/js/keyboard.js"></script>
6782
<script src="/js/back-button.js"></script>

layouts/index.html

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,3 @@
11
{{ define "main" -}}
2-
<div class="posts">
3-
{{ range .Data.Pages -}}
4-
<div class="post">
5-
<h1 class="post-title">
6-
<a href="{{ .Permalink }}">{{ .Title }}</a>
7-
</h1>
8-
<span class="post-date">{{ .Date.Format "Mon, Jan 2, 2006" }}</span>
9-
{{ .Summary }}
10-
{{ if .Truncated }}
11-
<div class="read-more-link">
12-
<a href="{{ .RelPermalink }}">Read More…</a>
13-
</div>
14-
{{ end }}
15-
</div>
2+
<div class="ignore">Ignore this landing page</div>
163
{{- end }}
17-
</div>
18-
{{- end }}

static/css/help.css

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -321,10 +321,14 @@ hr {
321321

322322
header nav {
323323
display: inline;
324-
padding: 4px 0 0px 0;
324+
/* padding: 4px 0 0px 0; */
325325
position: relative;
326326
}
327327

328+
#search, .algolia-autocomplete {
329+
vertical-align: middle;
330+
}
331+
328332
header nav input {
329333
font-size: 14px;
330334
font-family: system, "helvetica neue", sans-serif;
@@ -338,6 +342,7 @@ header nav a {
338342
position: relative;
339343
padding: 10px;
340344
margin-right: 10px;
345+
display: inline-block;
341346
/* padding-bottom: 0; */
342347
line-height: 1.2em;
343348
}

static/js/permalink.js

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
1-
function permalink(){
1+
function permalink() {
22
'use strict';
3-
/*global $*/
43
var anchor = document.createElement('a');
54
anchor.className = 'anchor';
65
anchor.innerHTML = '<span class="permalink"></span>';
76

8-
document.querySelectorAll('h1,h2,h3,h4,h5,h6').forEach(function (el) {
7+
document.querySelectorAll('h1,h2,h3,h4,h5,h6').forEach(function(el) {
98
if (el.id) {
109
var clone = anchor.cloneNode(true);
1110
clone.href = '#' + el.id;
@@ -16,4 +15,4 @@ function permalink(){
1615

1716
if (document.querySelector && Function.prototype.bind) {
1817
permalink();
19-
}
18+
}

0 commit comments

Comments
 (0)