Skip to content

Commit

Permalink
Enable CJK search
Browse files Browse the repository at this point in the history
  • Loading branch information
makenowjust committed Jan 29, 2024
1 parent 7cb9f63 commit 3a3ed54
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
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/allfunc/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.

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

0 comments on commit 3a3ed54

Please sign in to comment.