Skip to content

Commit

Permalink
I hear it can handle Japanese searches, so I'll give it a try 🦖
Browse files Browse the repository at this point in the history
refs: Support CJK (mutiple language) search #2052
rust-lang/mdBook#2052
  • Loading branch information
CoralPink committed Mar 28, 2023
1 parent 544ee59 commit 8e94446
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
2 changes: 1 addition & 1 deletion book.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ create-missing = false

[output.html]
additional-css = ["css/style.css"]
additional-js = ["js/dist/pagetoc.js"]
additional-js = ["js/dist/pagetoc.js", "js/assets/fzf.umd.js", "js/assets/elasticlunr.js"]
default-theme = "Latte"
preferred-dark-theme = "Macchiato"
git-repository-url = "https://github.com/CoralPink/commentary"
Expand Down
28 changes: 28 additions & 0 deletions js/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 js/assets/fzf.umd.js

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

0 comments on commit 8e94446

Please sign in to comment.