-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathplugin-search.js.patch
More file actions
43 lines (40 loc) · 1.81 KB
/
plugin-search.js.patch
File metadata and controls
43 lines (40 loc) · 1.81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
--- a/gitbook/js/plugin-search.js
+++ b/gitbook/js/plugin-search.js
@@ -46,7 +46,7 @@ gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
}
fuse = new Fuse(data.map((_data => {
return {
- url: _data[0],
+ urls: _data[0],
title: _data[1],
body: _data[2]
};
@@ -59,6 +59,7 @@ gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
},
_search.opts
));
+ $('li[data-path=""]').data('path', currentPath());
}
// Fetch the search index
@@ -73,8 +74,12 @@ gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
switch (_search.engine) {
case 'fuse':
if (!fuse) return;
- results = fuse.search(q).map(function(result) {
- var parts = result.item.url.split('#');
+ results = [].concat.apply([], fuse.search(q).map(function (result) {
+ return result.item.urls;
+ })).filter(function (url, index, array) {
+ return array.indexOf(url) == index;
+ }).map(function (url) {
+ var parts = url.split('#');
return {
path: parts[0],
hash: parts[1]
@@ -229,7 +234,7 @@ gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
// Type in search bar
- $(document).on("keyup", ".book-search input", function(e) {
+ $(document).on("keydown", ".book-search input", function(e) {
var key = (e.keyCode ? e.keyCode : e.which);
// [Yihui] Escape -> close search box; Up/Down/Enter: previous/next highlighted
if (key == 27) {