Skip to content

Commit 967acbe

Browse files
author
markzegarelli
authored
Merge pull request #1427 from segmentio/DOC_131-Algolia
Doc 131 algolia
2 parents e6767db + c9c8272 commit 967acbe

File tree

16 files changed

+12889
-27
lines changed

16 files changed

+12889
-27
lines changed

Gemfile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ group :jekyll_plugins do
1717
gem 'jekyll-redirect-from'
1818
gem "premonition", "~> 2.0.0"
1919
gem "jekyll-include-cache"
20+
gem 'jekyll-algolia'
2021
end
2122

2223
# Windows does not include zoneinfo files, so bundle the tzinfo-data gem

Gemfile.lock

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ GEM
2323
specs:
2424
addressable (2.7.0)
2525
public_suffix (>= 2.0.2, < 5.0)
26+
algolia_html_extractor (2.6.4)
27+
json (~> 2.0)
28+
nokogiri (~> 1.10)
29+
algoliasearch (1.27.5)
30+
httpclient (~> 2.8, >= 2.8.3)
31+
json (>= 1.5.1)
2632
colorator (1.1.0)
2733
commonmarker (0.21.0)
2834
ruby-enum (~> 0.5)
@@ -36,10 +42,21 @@ GEM
3642
multipart-post (>= 1.2, < 3)
3743
ruby2_keywords
3844
ffi (1.13.1)
45+
filesize (0.2.0)
3946
forwardable-extended (2.6.0)
4047
http_parser.rb (0.6.0)
48+
httpclient (2.8.3)
4149
i18n (1.8.5)
4250
concurrent-ruby (~> 1.0)
51+
jekyll-algolia (1.6.0)
52+
algolia_html_extractor (~> 2.6)
53+
algoliasearch (~> 1.26)
54+
filesize (~> 0.1)
55+
jekyll (>= 3.6, < 5.0)
56+
json (~> 2.0)
57+
nokogiri (~> 1.6)
58+
progressbar (~> 1.9)
59+
verbal_expressions (~> 0.1.5)
4360
jekyll-commonmark (1.3.1)
4461
commonmarker (~> 0.14)
4562
jekyll (>= 3.7, < 5.0)
@@ -56,6 +73,7 @@ GEM
5673
jekyll (>= 3.7, < 5.0)
5774
jekyll-watch (2.2.1)
5875
listen (~> 3.0)
76+
json (2.5.1)
5977
kramdown (2.3.0)
6078
rexml
6179
kramdown-parser-gfm (1.1.0)
@@ -67,12 +85,20 @@ GEM
6785
rb-fsevent (~> 0.10, >= 0.10.3)
6886
rb-inotify (~> 0.9, >= 0.9.10)
6987
mercenary (0.4.0)
88+
mini_portile2 (2.5.0)
7089
multipart-post (2.1.1)
90+
nokogiri (1.11.1)
91+
mini_portile2 (~> 2.5.0)
92+
racc (~> 1.4)
93+
nokogiri (1.11.1-x86_64-linux)
94+
racc (~> 1.4)
7195
pathutil (0.16.2)
7296
forwardable-extended (~> 2.6)
7397
posix-spawn (0.3.15)
7498
premonition (2.0.1)
99+
progressbar (1.11.0)
75100
public_suffix (4.0.6)
101+
racc (1.5.2)
76102
rake (13.0.1)
77103
rb-fsevent (0.10.4)
78104
rb-inotify (0.10.1)
@@ -93,6 +119,7 @@ GEM
93119
tzinfo-data (1.2020.4)
94120
tzinfo (>= 1.0.0)
95121
unicode-display_width (1.7.0)
122+
verbal_expressions (0.1.5)
96123
wdm (0.1.1)
97124

98125
PLATFORMS
@@ -103,6 +130,7 @@ DEPENDENCIES
103130
dotenv
104131
faraday
105132
jekyll!
133+
jekyll-algolia
106134
jekyll-commonmark
107135
jekyll-include-cache
108136
jekyll-last-modified-at

_config.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,3 +49,8 @@ plugins:
4949
- premonition
5050
- jekyll-commonmark
5151
- jekyll-last-modified-at
52+
algolia:
53+
application_id: UINQ2M4D9S
54+
index_name: segment-docs
55+
files_to_exclude:
56+
- _release_notes/*

js/algolia/index.js

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
import { html } from 'htm/preact';
2+
import algoliasearch from 'algoliasearch/lite';
3+
import { autocomplete, getAlgoliaHits, highlightHit } from '@algolia/autocomplete-js';
4+
import {createAlgoliaInsightsPlugin} from '@algolia/autocomplete-plugin-algolia-insights';
5+
import insightsClient from 'search-insights';
6+
7+
8+
const appId = 'UINQ2M4D9S';
9+
const apiKey = '636b6d9e2dfb207e89ea7344859848f9';
10+
const searchClient = algoliasearch(appId, apiKey);
11+
12+
//insights
13+
insightsClient('init', { appId, apiKey });
14+
const algoliaInsightsPlugin = createAlgoliaInsightsPlugin({ insightsClient });
15+
16+
17+
const search = autocomplete({
18+
container: '#autocomplete',
19+
placeholder: 'Search the Segment documentation',
20+
debug: false,
21+
openOnFocus: false,
22+
keyboardShortcuts: ['s', 191],
23+
plugins: [algoliaInsightsPlugin,],
24+
detachedMediaQuery:'none',
25+
getSources( {query} ) {
26+
return [
27+
{
28+
sourceId: 'articles',
29+
getItemUrl({ item }){
30+
if (item.anchor != null) {
31+
var itemUrl = item.url+"#" + item.anchor;
32+
} else {
33+
var itemUrl = item.url;
34+
}
35+
return itemUrl;
36+
},
37+
getItems() {
38+
return getAlgoliaHits({
39+
searchClient,
40+
queries: [
41+
{
42+
indexName: 'segment-docs',
43+
query,
44+
params: {
45+
hitsPerPage: 7,
46+
facetFilters: ['hidden:-true'],
47+
clickAnalytics: true,
48+
},
49+
},
50+
],
51+
});
52+
},
53+
templates: {
54+
item({ item }){
55+
if (item.anchor != null) {
56+
var anchorLink = "#" + item.anchor;
57+
} else {
58+
var anchorLink = "";
59+
}
60+
return html `<a class="aa-link" href="/docs${item.url}${anchorLink}">
61+
<p class="aa-title" >${highlightHit({hit: item, attribute: 'title'})}</h3>
62+
<p class="aa-heading">${item.headings.join(' >')}</p>
63+
<p class="aa-content">${highlightHit({hit: item, attribute: 'content'})}</p></a>
64+
`;
65+
},
66+
noResults() {
67+
return html `<p class="aa-content">No results for <strong>${query}</strong></p>`;
68+
}
69+
},
70+
71+
},
72+
];
73+
},
74+
navigator: {
75+
navigate({ itemUrl }) {
76+
window.location.assign('/docs'+itemUrl);
77+
},
78+
}
79+
});
80+

js/index.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import sideMenu from './side-menu'
1919
import tracking from './tracking'
2020
import searchBar from './search-bar'
2121
import glightbox from './glightbox'
22+
import autocomplete from './algolia'
2223
feedback()
2324
accordion()
2425
accordionGroup()
@@ -39,4 +40,4 @@ relativeLinks()
3940
sideMenu()
4041
tracking()
4142
searchBar()
42-
glightbox()
43+
glightbox()

netlify.toml

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,13 @@
11
[build]
2+
command = "jekyll algolia && yarn develop"
23
# Ignore builds unless [netlify-build] is present in commit message
34
# ignore = "git log -1 --pretty=%B | ( ! grep -q '\[netlify\-build\]' )"
45
# Ignore if [netlify-ignore] is present
56
ignore = "git log -1 --pretty=%B | ( grep -q '\\[netlify\\-ignore\\]' )"
67

8+
[context.deploy-preview]
9+
command = "yarn develop"
10+
711
[[redirects]]
812
from = "/docs/*"
913
to = "/:splat"
@@ -14,7 +18,3 @@
1418
to = "/assets/docs.bundle.js"
1519
status = 200
1620

17-
[[plugins]]
18-
package = "@algolia/netlify-plugin-crawler"
19-
[plugins.inputs]
20-
branches = ['DOC-65_Algolia-crawl']

0 commit comments

Comments
 (0)