Skip to content

Commit

Permalink
feat(search): 至少可以搜索中文了!
Browse files Browse the repository at this point in the history
Closes #9

See merge request huangjj27/huangjj27.gitlab.io!12
  • Loading branch information
huangjj27 committed Dec 9, 2023
2 parents ffdc9fb + ab4a13c commit 285b7b7
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 3 deletions.
3 changes: 1 addition & 2 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,7 @@ build:
pages:
stage: deploy
script:
- mdbook build
- mv book/html public
- mdbook build -d public
dependencies:
- build
rules:
Expand Down
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 285b7b7

Please sign in to comment.