Skip to content

Commit

Permalink
update supplement renders
Browse files Browse the repository at this point in the history
  • Loading branch information
pratikunterwegs committed Oct 7, 2021
1 parent d2d090b commit da7761e
Show file tree
Hide file tree
Showing 10 changed files with 984 additions and 1,039 deletions.
83 changes: 33 additions & 50 deletions docs/index.html

Large diffs are not rendered by default.

6 changes: 0 additions & 6 deletions docs/libs/gitbook-2.6.7/css/plugin-bookdown.css
Original file line number Diff line number Diff line change
Expand Up @@ -97,9 +97,3 @@ div.proof>*:last-child:after {
.header-section-number {
padding-right: .5em;
}
#header .multi-author {
margin: 0.5em 0 -0.5em 0;
}
#header .date {
margin-top: 1.5em;
}
7 changes: 7 additions & 0 deletions docs/libs/gitbook-2.6.7/js/lunr.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

93 changes: 23 additions & 70 deletions docs/libs/gitbook-2.6.7/js/plugin-search.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,9 @@
gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
var index = null;
var fuse = null;
var _search = {engine: 'lunr', opts: {}};
var $searchInput, $searchLabel, $searchForm;
var $highlighted = [], hi, hiOpts = { className: 'search-highlight' };
var collapse = false, toc_visible = [];

function init(config) {
// Instantiate search settings
_search = gitbook.storage.get("search", {
engine: config.search.engine || 'lunr',
opts: config.search.options || {},
});
};

// Save current search settings
function saveSearchSettings() {
gitbook.storage.set("search", _search);
}

// Use a specific index
function loadIndex(data) {
// [Yihui] In bookdown, I use a character matrix to store the chapter
Expand All @@ -29,36 +14,18 @@ gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
// lunr cannot handle non-English text very well, e.g. the default
// tokenizer cannot deal with Chinese text, so we may want to replace
// lunr with a dumb simple text matching approach.
if (_search.engine === 'lunr') {
index = lunr(function () {
this.ref('url');
this.field('title', { boost: 10 });
this.field('body');
});
data.map(function(item) {
index.add({
url: item[0],
title: item[1],
body: item[2]
});
index = lunr(function () {
this.ref('url');
this.field('title', { boost: 10 });
this.field('body');
});
data.map(function(item) {
index.add({
url: item[0],
title: item[1],
body: item[2]
});
return;
}
fuse = new Fuse(data.map((_data => {
return {
url: _data[0],
title: _data[1],
body: _data[2]
};
})), Object.assign(
{
includeScore: true,
threshold: 0.1,
ignoreLocation: true,
keys: ["title", "body"]
},
_search.opts
));
});
}

// Fetch the search index
Expand All @@ -69,33 +36,20 @@ gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {

// Search for a term and return results
function search(q) {
let results = [];
switch (_search.engine) {
case 'fuse':
if (!fuse) return;
results = fuse.search(q).map(function(result) {
var parts = result.item.url.split('#');
return {
path: parts[0],
hash: parts[1]
};
});
break;
case 'lunr':
default:
if (!index) return;
results = _.chain(index.search(q)).map(function(result) {
var parts = result.ref.split("#");
return {
path: parts[0],
hash: parts[1]
};
})
.value();
}
if (!index) return;

var results = _.chain(index.search(q))
.map(function(result) {
var parts = result.ref.split("#");
return {
path: parts[0],
hash: parts[1]
};
})
.value();

// [Yihui] Highlight the search keyword on current page
$highlighted = $('.page-inner')
$highlighted = results.length === 0 ? [] : $('.page-inner')
.unhighlight(hiOpts).highlight(q, hiOpts).find('span.search-highlight');
scrollToHighlighted(0);

Expand Down Expand Up @@ -218,7 +172,6 @@ gitbook.require(["gitbook", "lodash", "jQuery"], function(gitbook, _, $) {
gitbook.events.bind("start", function(e, config) {
// [Yihui] disable search
if (config.search === false) return;
init(config);
collapse = !config.toc || config.toc.collapse === 'section' ||
config.toc.collapse === 'subsection';

Expand Down
4 changes: 4 additions & 0 deletions docs/libs/jquery-2.2.3/jquery.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit da7761e

Please sign in to comment.