Skip to content

Commit 3a3ed54

Browse files
committed
Enable CJK search
Ref rust-lang/mdBook#2052
1 parent 7cb9f63 commit 3a3ed54

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

assets/elasticlunr.js

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/**
2+
* @see https://github.com/allfunc/docker-mdbook
3+
*/
4+
window.elasticlunr.Index.load = (index) => {
5+
const FzF = window.fzf.Fzf;
6+
const storeDocs = index.documentStore.docs;
7+
const indexArr = Object.keys(storeDocs);
8+
const ofzf = new FzF(indexArr, {
9+
selector: (item) => {
10+
const res = storeDocs[item];
11+
res.text = `${res.title}${res.breadcrumbs}${res.body}`;
12+
return res.text;
13+
},
14+
});
15+
return {
16+
search: (searchterm) => {
17+
const entries = ofzf.find(searchterm);
18+
return entries.map((data) => {
19+
const { item, score } = data;
20+
return {
21+
doc: storeDocs[item],
22+
ref: item,
23+
score,
24+
};
25+
});
26+
},
27+
};
28+
};

assets/fzf.umd.js

+6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

book.toml

+1
Original file line numberDiff line numberDiff line change
@@ -8,3 +8,4 @@ title = "作って学ぶ正規表現エンジン"
88
[output.html]
99
git-repository-url = "https://github.com/makenowjust/kantan-regex-book"
1010
edit-url-template = "https://github.com/makenowjust/kantan-regex-book/edit/main/{path}"
11+
additional-js = ["assets/fzf.umd.js", "assets/elasticlunr.js"]

0 commit comments

Comments
 (0)