Skip to content
This repository was archived by the owner on Apr 1, 2024. It is now read-only.

Commit cf89e2e

Browse files
trentmwillisKrinkle
authored andcommitted
Add Algolia search
Setup Travis to run algolia to index content for search. Ref #151.
1 parent 2cdec49 commit cf89e2e

File tree

7 files changed

+171
-5
lines changed

7 files changed

+171
-5
lines changed

.travis.yml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
language: ruby
2+
cache: bundler
3+
script:
4+
- bundle exec jekyll algolia
5+
branches:
6+
only:
7+
- master
8+
rvm:
9+
- 2.4

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,3 @@
11
source 'https://rubygems.org'
22
gem 'github-pages', group: :jekyll_plugins
3+
gem 'jekyll-algolia', group: :jekyll_plugins

Gemfile.lock

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ GEM
88
tzinfo (~> 1.1)
99
addressable (2.5.2)
1010
public_suffix (>= 2.0.2, < 4.0)
11+
algolia_html_extractor (2.5.2)
12+
json (~> 2.0)
13+
nokogiri (~> 1.8.2)
14+
algoliasearch (1.19.2)
15+
httpclient (~> 2.8, >= 2.8.3)
16+
json (>= 1.5.1)
1117
coffee-script (2.4.1)
1218
coffee-script-source
1319
execjs
@@ -26,6 +32,7 @@ GEM
2632
faraday (0.14.0)
2733
multipart-post (>= 1.2, < 3)
2834
ffi (1.9.23)
35+
filesize (0.1.1)
2936
forwardable-extended (2.6.0)
3037
gemoji (3.0.0)
3138
github-pages (180)
@@ -83,6 +90,7 @@ GEM
8390
activesupport (>= 2)
8491
nokogiri (>= 1.4)
8592
http_parser.rb (0.6.0)
93+
httpclient (2.8.3)
8694
i18n (0.9.5)
8795
concurrent-ruby (~> 1.0)
8896
jekyll (3.7.3)
@@ -98,6 +106,15 @@ GEM
98106
pathutil (~> 0.9)
99107
rouge (>= 1.7, < 4)
100108
safe_yaml (~> 1.0)
109+
jekyll-algolia (1.3.4)
110+
algolia_html_extractor (~> 2.5.2)
111+
algoliasearch (~> 1.18)
112+
filesize (~> 0.1)
113+
jekyll (~> 3.0)
114+
json (~> 2.0)
115+
nokogiri (~> 1.6)
116+
progressbar (~> 1.9)
117+
verbal_expressions (~> 0.1.5)
101118
jekyll-avatar (0.5.0)
102119
jekyll (~> 3.0)
103120
jekyll-coffeescript (1.1.1)
@@ -192,6 +209,7 @@ GEM
192209
gemoji (~> 3.0)
193210
html-pipeline (~> 2.2)
194211
jekyll (~> 3.0)
212+
json (2.1.0)
195213
kramdown (1.16.2)
196214
liquid (4.0.0)
197215
listen (3.1.5)
@@ -213,6 +231,7 @@ GEM
213231
sawyer (~> 0.8.0, >= 0.5.3)
214232
pathutil (0.16.1)
215233
forwardable-extended (~> 2.6)
234+
progressbar (1.9.0)
216235
public_suffix (2.0.5)
217236
rb-fsevent (0.10.3)
218237
rb-inotify (0.9.10)
@@ -239,12 +258,14 @@ GEM
239258
tzinfo (1.2.5)
240259
thread_safe (~> 0.1)
241260
unicode-display_width (1.3.0)
261+
verbal_expressions (0.1.5)
242262

243263
PLATFORMS
244264
ruby
245265

246266
DEPENDENCIES
247267
github-pages
268+
jekyll-algolia
248269

249270
BUNDLED WITH
250271
1.16.1

_config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ kramdown:
2828
input: GFM
2929
toc_levels: "1,2"
3030

31+
algolia: # Search
32+
application_id: HOJ487LP0L
33+
index_name: qunitjs
34+
search_only_api_key: aed00982db05bd21dd05310be057bda8
35+
3136
exclude:
3237
- Gemfile
3338
- Gemfile.lock

_includes/search.html

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
<div class="aa-input-container">
2+
<input type="search" id="aa-search-input" class="aa-input-search" placeholder="Search..." name="search" autocomplete="off">
3+
<svg class="aa-input-icon" viewBox="654 -372 1664 1664">
4+
<path d="M1806,332c0-123.3-43.8-228.8-131.5-316.5C1586.8-72.2,1481.3-116,1358-116s-228.8,43.8-316.5,131.5 C953.8,103.2,910,208.7,910,332s43.8,228.8,131.5,316.5C1129.2,736.2,1234.7,780,1358,780s228.8-43.8,316.5-131.5 C1762.2,560.8,1806,455.3,1806,332z M2318,1164c0,34.7-12.7,64.7-38,90s-55.3,38-90,38c-36,0-66-12.7-90-38l-343-342 c-119.3,82.7-252.3,124-399,124c-95.3,0-186.5-18.5-273.5-55.5s-162-87-225-150s-113-138-150-225S654,427.3,654,332 s18.5-186.5,55.5-273.5s87-162,150-225s138-113,225-150S1262.7-372,1358-372s186.5,18.5,273.5,55.5s162,87,225,150s113,138,150,225 S2062,236.7,2062,332c0,146.7-41.3,279.7-124,399l343,343C2305.7,1098.7,2318,1128.7,2318,1164z" />
5+
</svg>
6+
</div>
7+
8+
<script src="https://cdn.jsdelivr.net/combine/npm/[email protected],npm/[email protected]/dist/autocomplete.min.js" defer></script>
9+
<script>
10+
window.addEventListener('DOMContentLoaded', function setupSearch() {
11+
const client = algoliasearch('{{ site.algolia.application_id }}', '{{ site.algolia.search_only_api_key }}');
12+
const index = client.initIndex('{{ site.algolia.index_name }}');
13+
const autocompleteOptions = {
14+
hint: false,
15+
debug: true
16+
};
17+
const autocompleteSources = [
18+
{
19+
source: autocomplete.sources.hits(index, { hitsPerPage: 5 }),
20+
displayKey: '',
21+
templates: {
22+
suggestion(suggestion) {
23+
return `
24+
<a href="${suggestion.url}">
25+
<p class="aa-suggestion_content">${suggestion._highlightResult.content.value}</p>
26+
<p class="aa-suggestion_meta">${suggestion.title}</p>
27+
</a>
28+
`;
29+
},
30+
empty(query) {
31+
return `<div class="aa-empty">No results for "${query.query}".</div>`;
32+
}
33+
}
34+
}
35+
];
36+
autocomplete('#aa-search-input', autocompleteOptions, autocompleteSources)
37+
.on('autocomplete:selected', (event, suggestion) => window.location = suggestion.url);
38+
});
39+
</script>

_layouts/wrapper.html

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!doctype html>
22
<html lang="en">
3-
<head>
3+
<head>
44
<meta charset="utf-8">
55
<meta http-equiv="X-UA-Compatible" content="chrome=1">
66
<meta name="viewport" content="width=device-width, initial-scale=1.0">
@@ -12,8 +12,8 @@
1212
<meta name="twitter:card" content="summary_large_image">
1313
<meta name="twitter:description" content="API reference documentation for QUnit">
1414
<meta name="twitter:title" content="QUnit API Docs">
15-
</head>
16-
<body>
15+
</head>
16+
<body>
1717
<!-- <a class="a11y" href="#main">skip to content</a> -->
1818

1919
<header class="site-header" role="banner">
@@ -22,6 +22,10 @@
2222
<img src="/img/logo-with-colored-text.svg" alt="QUnit Logo">
2323
</a>
2424

25+
<div class="site-search">
26+
{% include search.html %}
27+
</div>
28+
2529
<nav class="site-nav">
2630
<ul class="site-nav-list">
2731
<li class="site-nav-item">
@@ -65,5 +69,5 @@
6569
<p class="copyright">Copyright &copy; 2018 <a href="https://js.foundation/" target="_blank" rel="noopener noreferrer">JS Foundation</a> and contributors</p>
6670
</div>
6771
</footer>
68-
</body>
69-
</html>
72+
</body>
73+
</html>

css/styles.scss

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,93 @@ iframe {
216216
color: $color-brand;
217217
}
218218

219+
/* Search */
220+
221+
.site-search {
222+
align-self: center;
223+
position: relative;
224+
}
225+
226+
.aa-input-container {
227+
display: inline-block;
228+
position: relative;
229+
}
230+
231+
.aa-input-search {
232+
width: 20rem;
233+
border: 1px solid $color-off-white;
234+
border-radius: 3px;
235+
padding: 12px 28px 12px 12px;
236+
-webkit-appearance: none;
237+
-moz-appearance: none;
238+
appearance: none;
239+
240+
&::-webkit-search-decoration,
241+
&::-webkit-search-cancel-button,
242+
&::-webkit-search-results-button,
243+
&::-webkit-search-results-decoration {
244+
display: none;
245+
}
246+
}
247+
248+
.aa-input-icon {
249+
height: 16px;
250+
width: 16px;
251+
position: absolute;
252+
top: 50%;
253+
right: 16px;
254+
transform: translateY(-50%);
255+
fill: #e4e4e4;
256+
}
257+
258+
.aa-dropdown-menu {
259+
background-color: $color-white;
260+
border-radius: 3px;
261+
min-width: 20rem;
262+
margin-top: $size-spacing;
263+
box-shadow: 0 10px 20px rgba(0,0,0,0.19), 0 6px 6px rgba(0,0,0,0.23);
264+
}
265+
266+
.aa-empty {
267+
padding: $size-spacing;
268+
}
269+
270+
.aa-suggestion {
271+
padding: $size-spacing;
272+
cursor: pointer;
273+
border-left: 2px solid transparent;
274+
border-right: 2px solid transparent;
275+
transition: background-color 0.2s, border-color 0.2s;
276+
277+
& + & {
278+
border-top: 1px solid $color-off-white;
279+
}
280+
281+
&:hover,
282+
&.aa-cursor {
283+
background-color: rgba($color-off-white, 0.5);
284+
border-left: 2px solid $color-brand;
285+
}
286+
}
287+
288+
.ais-Highlight {
289+
font-weight: bold;
290+
}
291+
292+
.aa-suggestion_content,
293+
.aa-suggestion_meta {
294+
margin-bottom: 0;
295+
color: $color-black;
296+
}
297+
298+
.aa-suggestion_meta {
299+
font-size: 0.8rem;
300+
color: $color-brand;
301+
border-top: 1px solid $color-off-white;
302+
margin-top: 0.25rem;
303+
padding-top: 0.25rem;
304+
}
305+
219306
/* Home Page Hero */
220307

221308
.hero {

0 commit comments

Comments
 (0)