8000 Improve CircleCI Docs Search Experience (#161) · github-cloud/circleci-docs@2ac80b5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 2ac80b5

Browse files
committed
Improve CircleCI Docs Search Experience (circleci#161)
Enables full text search for docs. Search priority is title, category, URL, then doc contents. Also, shows "No results found" when nothing comes up. Hopefully this reduces the number of people thinking the search box is broken.
1 parent 863dab0 commit 2ac80b5

File tree

3 files changed

+12
-5
lines changed

3 files changed

+12
-5
lines changed

jekyll/assets/css/main.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,9 @@ nav.sidebar{
6363
right: 10%;
6464
left: 10%;
6565
}
66+
#search-results li span{
67+
padding: 3px 20px;
68+
}
6669

6770

6871
// Article

jekyll/assets/js/search-index.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ layout: null
55
{% for doc in site.docs %}
66
"{{ doc.url | slugify }}":{
77
"title": "{{ doc.title | xml_escape }}",
8-
"url": "{{ site.baseurl }}{{ doc.url | xml_escape }}",
9-
"categories": "{{ doc.categories | join: ',' | xml_escape }}"
8+
"url": "{{ doc.url | xml_escape }}",
9+
"categories": "{{ doc.categories | join: ',' | xml_escape }}",
10+
"content": {{ doc.content | strip_html | strip_newlines | jsonify }}
1011
}
1112
{% unless forloop.last %},{% endunless %}
1213
{% endfor %}

jekyll/assets/js/search.js

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ jQuery(function(){
66
// a boost of 10 to indicate matches on it are more important.
77
window.idx = lunr(function () {
88
this.field('id');
9-
this.field('title', { boost: 10 });
10-
this.field('category');
9+
this.field('title', { boost: 20 });
10+
this.field('category', { boost: 10 });
11+
this.field('url', { boost: 5 });
12+
this.field('content');
1113
});
1214

1315
// Download the data from the JSON file we generated
@@ -58,7 +60,8 @@ jQuery(function(){
5860
$search_results.append(appendString);
5961
});
6062
}else{
61-
$search_results.toggle(false);
63+
$search_results.empty();
64+
$search_results.append('<li><span>No results found</span></li>');
6265
}
6366
});
6467
}

0 commit comments

Comments
 (0)
0