Skip to content

Commit e63b687

Browse files
committed
Fix the bugs caused by the jekyll algolia plugin
- Make search JavaScript more robust by checking if values are not undefined - Update the exluded files syntax
1 parent aef6f2d commit e63b687

File tree

4 files changed

+3853
-5
lines changed

4 files changed

+3853
-5
lines changed

Diff for: _config.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ algolia:
9292
index_name: 'devdocs'
9393
api_key: 'd2d0f33ab73e291ef8d88d8b565e754c'
9494
lazy_update: false
95-
excluded_files:
95+
files_to_exclude:
9696
- guides/m1x
9797
- swagger
9898

Diff for: _layouts/search.html

+7-1
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
var title_highlighted = item._highlightResult.title;
7979
var title_plain = item.title;
8080
var url = item.url;
81+
var content = '';
8182
// Check if we can show title, if not - at least show URL
8283
if (typeof title_highlighted !== 'undefined') {
8384
title = title_highlighted.value;
@@ -87,14 +88,19 @@
8788
title = url;
8889
}
8990

91+
// Check if we have the description of the hit
92+
if ( typeof item._highlightResult.content !== 'undefined' ) {
93+
content = item._highlightResult.content.value;
94+
}
95+
9096
//TODO: fix the baseurl on the entire site then remove this:
9197
if ( baseUrl == '/' ) {
9298
var link = '<a href="' + url + '">' + title +'</a>';
9399
} else {
94100
var link = '<a href="' + baseUrl + url + '">' + title +'</a>';
95101
}
96102

97-
return '<div class="hit"><h2 class="hit-name">'+ link + '</h2><div class="hit-url">'+ document.location.origin + url +'</div><div class="hit-content">'+ item._highlightResult.text.value + '</div></div>';
103+
return '<div class="hit"><h2 class="hit-name">'+ link + '</h2><div class="hit-url">'+ document.location.origin + url +'</div><div class="hit-content">'+ content + '</div></div>';
98104
},
99105
empty: '<div id="no-results-message"><p>No results found.</p></div>',
100106

Diff for: common/js/app.min.js

+3,841-1
Large diffs are not rendered by default.

Diff for: js/_includes/search.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,17 @@ $(function() {
5151
templates: {
5252
//'suggestion' templating function used to render a single suggestion
5353
suggestion: function(suggestion) {
54-
return '<a href="' + suggestion.url + '">' + suggestion._highlightResult.title.value + '</a>';
54+
var title = suggestion._highlightResult.title;
55+
if ( typeof title !== 'undefined') {
56+
return '<a href="' + suggestion.url + '">' + title.value + '</a>';
57+
}
5558
}
5659
}
5760
}
5861
]).on('autocomplete:selected', function ( event, suggestion, dataset ) {
5962
if ( typeof suggestion.url != 'undefined' ) {
6063
window.location.href = suggestion.url;
6164
}
62-
console.log(suggestion);
6365
}).on('keypress', function (event) {
6466
if(event.which == 13) {
6567
var value = escapeHTML(event.target.value);

0 commit comments

Comments
 (0)