additional-js

This commit is contained in:
Nebel 2024-02-06 14:27:48 +09:00
parent 9db04731b8
commit d39ad2f2f8
Signed by: nebel
GPG key ID: 79807D08C6EF6460
3 changed files with 34 additions and 4 deletions

View file

@ -1,10 +1,11 @@
[book] [book]
language = "ja"
title = "Hasuraで作るREST API"
authors = ["Kohei Watanabe"] authors = ["Kohei Watanabe"]
language = "ja"
src = "docs" src = "docs"
title = "Hasuraで作るREST API"
[output.html] [output.html]
site-url = "/hasura-rest-hands-on/" additional-js = ["external-links.js", "regexp-search.js"]
git-repository-url = "https://github.com/kou029w/hasura-rest-hands-on"
edit-url-template = "https://github.com/kou029w/hasura-rest-hands-on/edit/main/{path}" edit-url-template = "https://github.com/kou029w/hasura-rest-hands-on/edit/main/{path}"
git-repository-url = "https://github.com/kou029w/hasura-rest-hands-on"
site-url = "/hasura-rest-hands-on/"

13
external-links.js Normal file
View 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
View 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 }] : [];
},
);
},
});