mirror of
https://github.com/kou029w/hasura-rest-hands-on.git
synced 2025-01-17 23:55:12 +00:00
additional-js
This commit is contained in:
parent
9db04731b8
commit
d39ad2f2f8
3 changed files with 34 additions and 4 deletions
|
@ -1,10 +1,11 @@
|
|||
[book]
|
||||
language = "ja"
|
||||
title = "Hasuraで作るREST API"
|
||||
authors = ["Kohei Watanabe"]
|
||||
language = "ja"
|
||||
src = "docs"
|
||||
title = "Hasuraで作るREST API"
|
||||
|
||||
[output.html]
|
||||
site-url = "/hasura-rest-hands-on/"
|
||||
git-repository-url = "https://github.com/kou029w/hasura-rest-hands-on"
|
||||
additional-js = ["external-links.js", "regexp-search.js"]
|
||||
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
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