Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/yanlinlin82/simple-style.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinlin Yan <yanlinlin82@gmail.com>2022-04-05 04:28:47 +0300
committerLinlin Yan <yanlinlin82@gmail.com>2022-04-05 04:28:47 +0300
commit5caf2fb8db7cb16f12a43af72a2e1ac860d81f57 (patch)
treea51feacc18f6d3cef1dc63bc0937030211341477
parentcfedd707ac31fc3f82c7b812ae72c385779cc134 (diff)
Support different search engine.
-rw-r--r--layouts/_default/baseof.html14
-rw-r--r--layouts/partials/search.html18
2 files changed, 19 insertions, 13 deletions
diff --git a/layouts/_default/baseof.html b/layouts/_default/baseof.html
index 033c397..b4d5b73 100644
--- a/layouts/_default/baseof.html
+++ b/layouts/_default/baseof.html
@@ -27,7 +27,19 @@
{{- range .Site.Menus.main -}}
<a href="{{ .URL }}">{{ .Name }}</a>
{{- end -}}
- {{ partial "search.html" -}}
+ {{ if isset site.Params "search" -}}
+ {{ if eq site.Params.Search "baidu" -}}
+ {{ partial "search.html" (dict "url" "https://www.baidu.com/s" "key" "wd") -}}
+ {{ else if eq site.Params.Search "google" -}}
+ {{ partial "search.html" (dict "url" "https://www.google.com/search" "key" "q") -}}
+ {{ else if eq site.Params.Search "bing" -}}
+ {{ partial "search.html" (dict "url" "https://www.bing.com/search" "key" "q") -}}
+ {{ else if eq site.Params.Search "duckduckgo" -}}
+ {{ partial "search.html" (dict "url" "https://www.duckduckgo.com/" "key" "q") -}}
+ {{ else -}}
+ {{ errorf "Unknown 'Site.Params.Search' value '%s'! Only 'baidu' is supported now." site.Params.Search -}}
+ {{ end -}}
+ {{ end -}}
</nav>
</header>
<main>
diff --git a/layouts/partials/search.html b/layouts/partials/search.html
index 4156a96..9f56b98 100644
--- a/layouts/partials/search.html
+++ b/layouts/partials/search.html
@@ -1,27 +1,21 @@
-{{ if isset site.Params "search" -}}
-{{ if eq site.Params.Search "baidu" -}}
<div class="search">
<script>
function check_search() {
- var s = document.getElementById('keyword').value;
+ var s = document.getElementById('_display_keyword').value;
s = s.replace(/(^\s*)|(\s*$)/g, '');
if (s == '' || s == undefined || s == null) {
- document.getElementById('keyword').focus();
+ document.getElementById('_display_keyword').focus();
return false;
}
- document.getElementById('wd').value = s + " site:{{ site.BaseURL }}";
+ document.getElementById('{{ .key }}').value = s + " site:{{ site.BaseURL }}";
return true;
}
</script>
- <form class="search" action="https://www.baidu.com/s" target="_blank" onsubmit="return check_search()">
- <input id="keyword" type="text" placeholder="Search.." name="keyword">
- <input id="wd" type="hidden" name="wd">
+ <form class="search" action="{{ .url }}" target="_blank" onsubmit="return check_search()">
+ <input id="_display_keyword" type="text" placeholder="Search.." name="keyword">
+ <input id="{{ .key }}" type="hidden" name="{{ .key }}">
<button type="submit"><svg focusable="false" xmlns="http://www.w3.org/2000/svg" viewBox="0 0 24 24" style="width:20px;height:20px;color:#333">
<path d="M15.5 14h-.79l-.28-.27A6.471 6.471 0 0 0 16 9.5 6.5 6.5 0 1 0 9.5 16c1.61 0 3.09-.59 4.23-1.57l.27.28v.79l5 4.99L20.49 19l-4.99-5zm-6 0C7.01 14 5 11.99 5 9.5S7.01 5 9.5 5 14 7.01 14 9.5 11.99 14 9.5 14z"></path>
</svg></button>
</form>
</div>
-{{ else -}}
-{{ errorf "Unknown 'Site.Params.Search' value '%s'! Only 'baidu' is supported now." site.Params.Search }}
-{{ end -}}
-{{ end -}}