summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSerghei Iakovlev <egrep@protonmail.ch>2022-07-10 20:13:20 +0200
committerSerghei Iakovlev <egrep@protonmail.ch>2022-07-10 20:13:20 +0200
commit7425b5f0498909087628465dfe6e6bfa4c42a422 (patch)
tree719f2e77660eb82a617184a49937d5d84747a0d8
parent05a643db54d7349c8c44f819737e48ff5555f9ff (diff)
downloadgohugo-theme-ed-7425b5f0498909087628465dfe6e6bfa4c42a422.tar.gz
Simplify search page
-rw-r--r--assets/js/search.js20
-rw-r--r--i18n/en.toml5
-rw-r--r--i18n/ru.toml5
-rw-r--r--layouts/partials/search-results.html9
-rw-r--r--layouts/shortcodes/form-search.html15
5 files changed, 18 insertions, 36 deletions
diff --git a/assets/js/search.js b/assets/js/search.js
index 4a2a815..b8c8c80 100644
--- a/assets/js/search.js
+++ b/assets/js/search.js
@@ -153,7 +153,6 @@ function handleClearSearchButtonClicked() {
}
function hideSearchResults() {
- document.getElementById('clear-search-results').classList.add('hide-element');
document.getElementById('site-search').classList.remove('expanded');
document.getElementById('search-results').classList.add('hide-element');
}
@@ -284,7 +283,6 @@ function chunkify(input, chunkSize) {
function showSearchResults() {
document.getElementById('search-results').classList.remove('hide-element');
document.getElementById('site-search').classList.remove('expanded');
- document.getElementById('clear-search-results').classList.remove('hide-element');
}
function scrollToTop() {
@@ -308,10 +306,14 @@ function ellipsize(input, maxLength) {
}
// RegExp.escape() polyfill
-if (!RegExp.escape) {
+//
+// For more see:
+// - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Escaping
+// - https://github.com/benjamingr/RegExp.escape/issues/37
+if (!Object.prototype.hasOwnProperty.call(RegExp, 'escape')) {
RegExp.escape = function(str) {
// $& means the whole matched string
- return str.replace(/[.*+?^${}()|[\]\\]/g, '\\$&');
+ return str.replace(/[.*+\-?^${}()|[\]\\]/g, '\\$&');
};
}
@@ -348,13 +350,5 @@ document.addEventListener('DOMContentLoaded', function () {
e.preventDefault();
});
- searchInput.addEventListener('keydown', (e) => {
- if (e.key === 'Enter') {
- handleSearchQuery(e);
- }
- });
-
- document
- .getElementById('clear-search-results')
- .addEventListener('click', () => handleClearSearchButtonClicked());
+ searchInput.addEventListener('keyup', (e) => handleSearchQuery(e));
});
diff --git a/i18n/en.toml b/i18n/en.toml
index f65d31f..24ef81d 100644
--- a/i18n/en.toml
+++ b/i18n/en.toml
@@ -53,14 +53,11 @@
other = 'Contents'
[search_help]
- other = "To search the site, enter a search term and press Enter."
+ other = "To search the site, enter a search term."
[search_site]
other = 'Search site'
-[clear_search_results]
- other = 'New Search'
-
[search_enter_term]
other = 'Please enter a search term.'
diff --git a/i18n/ru.toml b/i18n/ru.toml
index 1bbb38e..dc47e82 100644
--- a/i18n/ru.toml
+++ b/i18n/ru.toml
@@ -53,14 +53,11 @@
other = 'Содержание'
[search_help]
- other = "Для поиска по сайту введите поисковый запрос и нажмите Enter."
+ other = "Для поиска по сайту введите поисковый запрос."
[search_site]
other = 'Поиск по сайту'
-[clear_search_results]
- other = 'Новый поиск'
-
[search_enter_term]
other = 'Введите поисковый запрос.'
diff --git a/layouts/partials/search-results.html b/layouts/partials/search-results.html
deleted file mode 100644
index fd4c48d..0000000
--- a/layouts/partials/search-results.html
+++ /dev/null
@@ -1,9 +0,0 @@
-<section id="search-results" class="hide-element">
- <div id="search-results-header">
- <div class="search-query search-query-right">
- <span id="results-count-text">{{ i18n "search_results" }}</span>
- <span id="results-count"></span>
- </div>
- </div>
- <div id="search-results-body" class="post-list"></div>
-</section>
diff --git a/layouts/shortcodes/form-search.html b/layouts/shortcodes/form-search.html
index e9a9175..f328f38 100644
--- a/layouts/shortcodes/form-search.html
+++ b/layouts/shortcodes/form-search.html
@@ -10,14 +10,17 @@
</div>
</div>
</form>
- <div id="clear-search-results" class="form-item hide-element">
- <button class="button button-large" type="reset">
- {{ i18n "clear_search_results" }}
- </button>
- </div>
</div>
-{{- partial "search-results" . -}}
+<section id="search-results" class="hide-element">
+ <div id="search-results-header">
+ <div class="search-query search-query-right">
+ <span id="results-count-text">{{ i18n "search_results" }}</span>
+ <span id="results-count"></span>
+ </div>
+ </div>
+ <div id="search-results-body" class="post-list"></div>
+</section>
{{- $vendors := slice (resources.Get "js/vendor/lunr.js") -}}
{{- $vendors = $vendors | append (resources.Get "js/vendor/lunr.multi.js" ) -}}