-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from hmatsu47/feature-23-search-box
refs #23 検索仮実装
- Loading branch information
Showing
3 changed files
with
85 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--- | ||
title: "全てのカテゴリから検索" | ||
draft: false | ||
--- | ||
<input id = "query" onkeyup="search(this.value)" size="28" autocomplete="off" autofocus placeholder="検索キーワードを入れてください" /> | ||
|
||
<script> | ||
// 検索 | ||
function search(query) { | ||
$(".card").each(function(i, elem) { | ||
var question = $(elem).find("span").text().toLowerCase(); | ||
var answer = $(elem).find(".card-body").text().toLowerCase(); | ||
if (query == "" || (question.indexOf(query) == -1 && answer.indexOf(query) == -1)) { | ||
$(elem).css("display", "none"); | ||
} else { | ||
$(elem).css("display", "block"); | ||
} | ||
}) | ||
} | ||
// ハッシュフラグメントの値で検索を実行 | ||
function searchWithHash() { | ||
const hash = decodeURI(location.hash.substring(1)); | ||
search(hash); | ||
// 必要があれば input 要素の値を更新 | ||
const queryElem = document.getElementById('query'); | ||
if (queryElem.value !== hash) { | ||
queryElem.value = hash; | ||
} | ||
} | ||
// ハッシュフラグメント付きの URL でページを開いたときに検索 | ||
window.addEventListener('DOMContentLoaded', searchWithHash); | ||
// ページ表示後にハッシュフラグメントが変化したら検索 | ||
window.addEventListener('hashchange', searchWithHash); | ||
</script> | ||
|
||
{{< result >}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{{ $_hugo_config := `{ "version": 1 }` }} | ||
{{ range $faq := (where $.Site.Data.faq.faq "カテゴリ名" "!=" "") }} | ||
<div class="card mb-4 rounded-0 shadow border-0" style="display: none;"> | ||
<div class="card-header rounded-0 bg-white border p-0 border-0"> | ||
<a class="card-link h4 d-flex tex-dark mb-0 py-3 px-4 justify-content-between" data-toggle="collapse" | ||
href="#{{ $faq.質問 | sha1 }}"> | ||
<span>{{ $faq.質問 }}</span> <i class="ti-plus text-primary text-right"></i> | ||
</a> | ||
</div> | ||
<div id="{{ $faq.質問 | sha1 }}" class="collapse" data-parent="#accordion"> | ||
<div class="card-body font-secondary text-color pt-0" style="white-space:pre-wrap; margin-bottom: 0px;">{{ $faq.回答 | markdownify }}</div> | ||
<div class="card-footer rounded-0 bg-white border p-0 border-0" style="text-align: right; margin-bottom: 0px; margin-right: 20px;"> | ||
{{ if eq (len $faq.更新日) 8 }} | ||
最終更新日:{{ slicestr $faq.更新日 0 4 }}年{{ slicestr $faq.更新日 4 6 | strings.TrimLeft "0" }}月{{ slicestr $faq.更新日 6 | strings.TrimLeft "0" }}日 | ||
{{ end}} | ||
<br/> | ||
<br/> | ||
</div> | ||
</div> | ||
{{ .Inner }} | ||
</div> | ||
{{ end }} |