mirror of
https://github.com/kou029w/nodejs-hands-on.git
synced 2025-01-18 08:05:10 +00:00
additional-js
This commit is contained in:
parent
fca7481ef2
commit
c8688c941e
3 changed files with 33 additions and 3 deletions
|
@ -1,9 +1,10 @@
|
||||||
[book]
|
[book]
|
||||||
|
authors = ["Kohei Watanabe"]
|
||||||
language = "ja"
|
language = "ja"
|
||||||
title = "Node.jsを使う"
|
title = "Node.jsを使う"
|
||||||
authors = ["Kohei Watanabe"]
|
|
||||||
|
|
||||||
[output.html]
|
[output.html]
|
||||||
site-url = "/nodejs-hands-on/"
|
additional-js = ["external-links.js", "regexp-search.js"]
|
||||||
git-repository-url = "https://github.com/kou029w/nodejs-hands-on"
|
|
||||||
edit-url-template = "https://github.com/kou029w/nodejs-hands-on/edit/main/{path}"
|
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/"
|
||||||
|
|
13
external-links.js
Normal file
13
external-links.js
Normal file
|
@ -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";
|
||||||
|
});
|
||||||
|
});
|
16
regexp-search.js
Normal file
16
regexp-search.js
Normal file
|
@ -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 }] : [];
|
||||||
|
},
|
||||||
|
);
|
||||||
|
},
|
||||||
|
});
|
Loading…
Add table
Reference in a new issue