Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refs #23 検索仮実装 #67

Merged
merged 8 commits into from
Dec 21, 2021
36 changes: 36 additions & 0 deletions content/search/_index.ja.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
---
title: "全てのカテゴリから検索"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ページタイトルですが、

ワクチン接種証明書アプリFAQ - 全てのカテゴリから検索

のほうがいいかな?と思いましたがどうでしょうか。

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGMT

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

どうでしょうね?
ヘッダに書かれている分冗長になるかな、とも思ったのですが。

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

https://test.d2qv7xiwv4i3gl.amplifyapp.com/faq1/
この辺のタイトルもアプリ名称ないので、まぁ、いいか。

もしやるにしても、別チケットにしましょう!

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 >}}
32 changes: 27 additions & 5 deletions layouts/partials/banner.html
Original file line number Diff line number Diff line change
@@ -1,11 +1,33 @@
{{ "<!-- banner -->" | safeHTML }}
<div class="container section">
<div class="container section" style="padding-bottom: 24px;">
<div class="row">
<div class="col-lg-8 text-center mx-auto">
<h1 class="text-white mb-3">{{ .Site.Params.banner.title | markdownify }}</h1>
<p class="text-white mb-4">{{ .Site.Params.banner.subtitle | markdownify }}</p>
<!-- <div class="position-relative">
<input id="search" class="form-control" placeholder="{{ .Site.Params.banner.placeholder }}">
<div class="position-relative">
<form>
<input id="searchKeyword" class="form-control" style="margin-top: 16px;" placeholder="検索キーワードを入れてください">
<i class="ti-search search-icon"></i>
<input id="searchButton" type="submit" value="" style="background-color: transparent; border: transparent;">
</form>

<script>
const SEARCH_URL = '/vaccinecert-faq/search/';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

/vaccinecert-faq 要らないのでは?


window.addEventListener('DOMContentLoaded', () => {
const searchButton = document.getElementById('searchButton');
const searchKeyword = document.getElementById('searchKeyword');

// 検索ボタンのクリックで検索ページへジャンプ
searchButton.addEventListener('click', e => {
e.preventDefault(); // Prevent default form's behavior
const query = searchKeyword.value;
const url = query ? SEARCH_URL + '#' + query : SEARCH_URL;
location.href = url;
});
});
</script>
<!-- <input id="search" class="form-control" placeholder="{{ .Site.Params.banner.placeholder }}">
<i class="ti-search search-icon"></i> -->
<!-- Javascript -->
<!-- {{ $currentNode := . }}
Expand All @@ -31,8 +53,8 @@ <h1 class="text-white mb-3">{{ .Site.Params.banner.title | markdownify }}</h1>
.appendTo( ul );
};
});
</script>
</div> -->
</script> -->
</div>
</div>
</div>
</div>
Expand Down
22 changes: 22 additions & 0 deletions layouts/shortcodes/result.html
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" }}日&nbsp;
{{ end}}
<br/>
<br/>
</div>
</div>
{{ .Inner }}
</div>
{{ end }}