diff --git a/book.toml b/book.toml index 8f329a7..4ed03cb 100644 --- a/book.toml +++ b/book.toml @@ -1,9 +1,10 @@ [book] +authors = ["Kohei Watanabe"] language = "ja" title = "Node.jsを使う" -authors = ["Kohei Watanabe"] [output.html] -site-url = "/nodejs-hands-on/" -git-repository-url = "https://github.com/kou029w/nodejs-hands-on" +additional-js = ["external-links.js", "regexp-search.js"] edit-url-template = "https://github.com/kou029w/nodejs-hands-on/edit/main/{path}" +git-repository-url = "https://github.com/kou029w/nodejs-hands-on" +site-url = "/nodejs-hands-on/" diff --git a/external-links.js b/external-links.js new file mode 100644 index 0000000..97590dc --- /dev/null +++ b/external-links.js @@ -0,0 +1,13 @@ +"use strict"; + +// 外部リンクを新しいブラウザーコンテキストで開く +window.addEventListener("DOMContentLoaded", () => { + const selector = ["http:", "https:"] + .map((scheme) => `a[href^="${scheme}"]`) + .join(","); + + document.querySelectorAll(selector).forEach((a) => { + a.target = "_blank"; + a.rel = "noreferrer"; + }); +}); diff --git a/regexp-search.js b/regexp-search.js new file mode 100644 index 0000000..46e45f4 --- /dev/null +++ b/regexp-search.js @@ -0,0 +1,16 @@ +"use strict"; + +// 正規表現検索を有効化 +window.elasticlunr.Index.load = (index) => ({ + search(keyword) { + const regexp = new RegExp(keyword, "gi"); + + return [...Object.entries(index.documentStore.docs)].flatMap( + ([ref, doc]) => { + const match = `${doc.title} ${doc.body}`.match(regexp); + + return match ? [{ ref, doc, score: match.length }] : []; + }, + ); + }, +});