chapter 1 finished

This commit is contained in:
2021-09-16 16:49:10 +02:00
parent ae2ef67a05
commit e7a6189645
54 changed files with 25323 additions and 626 deletions

View File

@ -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;
}

File diff suppressed because one or more lines are too long

View File

@ -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
@ -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');
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]
});
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
@ -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);
@ -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';

View File

@ -0,0 +1,12 @@
// Pandoc 2.9 adds attributes on both header and div. We remove the former (to
// be compatible with the behavior of Pandoc < 2.8).
document.addEventListener('DOMContentLoaded', function(e) {
var hs = document.querySelectorAll("div.section[class*='level'] > :first-child");
var i, h, a;
for (i = 0; i < hs.length; i++) {
h = hs[i];
if (!/^h[1-6]$/i.test(h.tagName)) continue; // it should be a header h1-h6
a = h.attributes;
while (a.length > 0) h.removeAttribute(a[0].name);
}
});

4
docs/libs/jquery-2.2.3/jquery.min.js vendored Normal file

File diff suppressed because one or more lines are too long