Skip to content

Commit

Permalink
feat(search): 至少可以搜索中文了!
Browse files Browse the repository at this point in the history
虽然搜索中文的时候会一整端给你高亮,但至少是能用了

close #9
  • Loading branch information
huangjj27 committed Dec 9, 2023
1 parent 0bcd890 commit ab4a13c
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 1 deletion.
28 changes: 28 additions & 0 deletions assets/elasticlunr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/**
* @see https://github.com/HillLiu/docker-mdbook
*/
window.elasticlunr.Index.load = (index) => {
const FzF = window.fzf.Fzf;
const storeDocs = index.documentStore.docs;
const indexArr = Object.keys(storeDocs);
const ofzf = new FzF(indexArr, {
selector: (item) => {
const res = storeDocs[item];
res.text = `${res.title}${res.breadcrumbs}${res.body}`;
return res.text;
},
});
return {
search: (searchterm) => {
const entries = ofzf.find(searchterm);
return entries.map((data) => {
const { item, score } = data;
return {
doc: storeDocs[item],
ref: item,
score,
};
});
},
};
};
6 changes: 6 additions & 0 deletions assets/fzf.umd.js

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

12 changes: 11 additions & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ edition = "2021"
[output.html]
mathjax-support = true
no-section-label = true
additional-js = ["assets/fzf.umd.js", "assets/elasticlunr.js"]
git-repository-url = "https://gitlab.com/huangjj27/huangjj27.gitlab.io"
git-repository-icon = "fa-gitlab"

Expand All @@ -27,4 +28,13 @@ copy-js = true
line-numbers = false

[output.html.search]
enable = false # wait for a usable chinese searching plugin!
enable = true
limit-results = 30
teaser-word-count = 30
use-boolean-and = true
boost-title = 2
boost-hierarchy = 1
boost-paragraph = 1
expand = true
heading-split-level = 3
copy-js = true

0 comments on commit ab4a13c

Please sign in to comment.