summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authoramzrk22020-06-16 00:47:55 +0800
committeramzrk22020-06-16 00:47:55 +0800
commite7587236dbe98775315619d4f3b8d3f335001583 (patch)
treec5ab5902569a79d66e2ff5144158b6fd0133fb03
parenta3376d1ad133455b73ca893e222c1aec89ae6d44 (diff)
downloadhugo-theme-fuji-e7587236dbe98775315619d4f3b8d3f335001583.tar.gz
hugo-theme-fuji-e7587236dbe98775315619d4f3b8d3f335001583.tar.bz2
hugo-theme-fuji-e7587236dbe98775315619d4f3b8d3f335001583.zip
Update tags in search template
-rw-r--r--assets/js/fuji.js6
-rw-r--r--layouts/_default/search.html2
-rw-r--r--layouts/partials/scripts-end.html8
-rw-r--r--static/assets/js/fuji.min.js2
4 files changed, 13 insertions, 5 deletions
diff --git a/assets/js/fuji.js b/assets/js/fuji.js
index d1be458..55e93b5 100644
--- a/assets/js/fuji.js
+++ b/assets/js/fuji.js
@@ -93,12 +93,14 @@ function searchAll(key, index) {
console.log(result);
if (result.length > 0) {
document.getElementById('search-result').innerHTML = template('search-result-template', result);
+ } else {
+ document.getElementById('search-result').innerHTML = '<span>NOT FOUND</span>';
}
}
let urlParams = new URLSearchParams(window.location.search); // get params from URL
-if (urlParams.has('search')) {
- let key = urlParams.get('search'); // get search keyword
+if (urlParams.has('s')) {
+ let key = urlParams.get('s'); // get search keyword
document.querySelector('.search-input input').setAttribute('value', key);
// get search index from json
let xhr = new XMLHttpRequest();
diff --git a/layouts/_default/search.html b/layouts/_default/search.html
index f9c808c..0911f06 100644
--- a/layouts/_default/search.html
+++ b/layouts/_default/search.html
@@ -3,7 +3,7 @@
<div class="page-info">
<form class="search-form" method="GET">
<div class="search-input">
- <input name="search" type="text" autocapitalize="off" autocomplete="off" autocorrect="off"
+ <input name="s" type="text" autocapitalize="off" autocomplete="off" autocorrect="off"
spellcheck="false" />
</div>
<div class="search-submit">
diff --git a/layouts/partials/scripts-end.html b/layouts/partials/scripts-end.html
index 1cd0c62..69c5dca 100644
--- a/layouts/partials/scripts-end.html
+++ b/layouts/partials/scripts-end.html
@@ -12,7 +12,13 @@
<a href="<%= $data[i].item.permalink %>">{{ "<%= $data[i].item.title %>" | safeHTML }}</a>
</h3>
<div class="post-item post-meta-archive">
- {{ "<%= $data[i].item.tags %>" | safeHTML }}
+ {{ "<% if ($data[i].item.tags && $data[i].item.tags.length > 0) { %>" | safeHTML }}
+ {{ "<% for(var j = 0; j < $data[i].item.tags.length; j++){ %>" | safeHTML }}
+ {{ "<%= $data[i].item.tags[j] %>" | safeHTML }}
+ {{ "<% } %>" | safeHTML }}
+ {{ "<% } else { %>" | safeHTML }}
+ No Tag
+ {{ "<% } %>" | safeHTML }}
</div>
</div>
{{ "<% } %>" | safeHTML }}
diff --git a/static/assets/js/fuji.min.js b/static/assets/js/fuji.min.js
index c21a20f..6044b49 100644
--- a/static/assets/js/fuji.min.js
+++ b/static/assets/js/fuji.min.js
@@ -1 +1 @@
-"use strict";function getNowTheme(){var e=document.body.getAttribute("data-theme");return"auto"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":"dark"===e?"dark":"light"}function updateUtterancesTheme(e){var t=getNowTheme();e&&("dark"===t?e.contentWindow.postMessage({type:"set-theme",theme:"photon-dark"},"https://utteranc.es"):e.contentWindow.postMessage({type:"set-theme",theme:"github-light"},"https://utteranc.es"))}function searchAll(e,t){var o=new Fuse(t,{keys:["title","tags"]}).search(e);console.log(o),0<o.length&&(document.getElementById("search-result").innerHTML=template("search-result-template",o))}document.querySelector("span.post-comment-notloaded")&&document.querySelector("span.post-comment-notloaded").addEventListener("click",loadComment),document.querySelector(".btn .btn-scroll-top").addEventListener("click",function(){document.documentElement.scrollTop=0}),document.querySelector(".btn .btn-toggle-mode").addEventListener("click",function(){var e=getNowTheme(),t=document.body.getAttribute("data-theme"),o=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";"auto"===t?(document.body.setAttribute("data-theme","light"===e?"dark":"light"),localStorage.setItem("fuji_data-theme","light"===e?"dark":"light")):"light"===t?(document.body.setAttribute("data-theme","dark"),localStorage.setItem("fuji_data-theme","dark"==o?"auto":"dark")):(document.body.setAttribute("data-theme","light"),localStorage.setItem("fuji_data-theme","light"==o?"auto":"light"));var r=document.querySelector(".post-comment");r&&document.querySelector("span.post-comment-notloaded").getAttribute("style")&&("utterances"===r.getAttribute("data-comment")&&updateUtterancesTheme(document.querySelector(".post-comment iframe")),"disqus"===r.getAttribute("data-comment")&&DISQUS.reset({reload:!0}))});var key,xhr,urlParams=new URLSearchParams(window.location.search);urlParams.has("search")&&(key=urlParams.get("search"),document.querySelector(".search-input input").setAttribute("value",key),(xhr=new XMLHttpRequest).open("GET","/index.json",!0),xhr.responseType="json",xhr.onerror=function(e){console.error("".concat(xhr.status," ").concat(xhr.statusText))},xhr.onload=function(){4===xhr.readyState&&(200===xhr.status?(console.log(xhr.response),searchAll(key,xhr.response)):console.error("".concat(xhr.status," ").concat(xhr.statusText)))},xhr.send(null)); \ No newline at end of file
+"use strict";function getNowTheme(){var e=document.body.getAttribute("data-theme");return"auto"===e?window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light":"dark"===e?"dark":"light"}function updateUtterancesTheme(e){var t=getNowTheme();e&&("dark"===t?e.contentWindow.postMessage({type:"set-theme",theme:"photon-dark"},"https://utteranc.es"):e.contentWindow.postMessage({type:"set-theme",theme:"github-light"},"https://utteranc.es"))}function searchAll(e,t){var o=new Fuse(t,{keys:["title","tags"]}).search(e);console.log(o),0<o.length?document.getElementById("search-result").innerHTML=template("search-result-template",o):document.getElementById("search-result").innerHTML="<span>NOT FOUND</span>"}document.querySelector("span.post-comment-notloaded")&&document.querySelector("span.post-comment-notloaded").addEventListener("click",loadComment),document.querySelector(".btn .btn-scroll-top").addEventListener("click",function(){document.documentElement.scrollTop=0}),document.querySelector(".btn .btn-toggle-mode").addEventListener("click",function(){var e=getNowTheme(),t=document.body.getAttribute("data-theme"),o=window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light";"auto"===t?(document.body.setAttribute("data-theme","light"===e?"dark":"light"),localStorage.setItem("fuji_data-theme","light"===e?"dark":"light")):"light"===t?(document.body.setAttribute("data-theme","dark"),localStorage.setItem("fuji_data-theme","dark"==o?"auto":"dark")):(document.body.setAttribute("data-theme","light"),localStorage.setItem("fuji_data-theme","light"==o?"auto":"light"));var r=document.querySelector(".post-comment");r&&document.querySelector("span.post-comment-notloaded").getAttribute("style")&&("utterances"===r.getAttribute("data-comment")&&updateUtterancesTheme(document.querySelector(".post-comment iframe")),"disqus"===r.getAttribute("data-comment")&&DISQUS.reset({reload:!0}))});var key,xhr,urlParams=new URLSearchParams(window.location.search);urlParams.has("s")&&(key=urlParams.get("s"),document.querySelector(".search-input input").setAttribute("value",key),(xhr=new XMLHttpRequest).open("GET","/index.json",!0),xhr.responseType="json",xhr.onerror=function(e){console.error("".concat(xhr.status," ").concat(xhr.statusText))},xhr.onload=function(){4===xhr.readyState&&(200===xhr.status?(console.log(xhr.response),searchAll(key,xhr.response)):console.error("".concat(xhr.status," ").concat(xhr.statusText)))},xhr.send(null)); \ No newline at end of file