mirror of
https://github.com/CaiJimmy/hugo-theme-stack.git
synced 2025-04-29 20:13:31 +08:00
Deal with blank search
This commit is contained in:
parent
7e697d1857
commit
5104df824f
@ -131,11 +131,11 @@ class Search {
|
|||||||
|
|
||||||
private async searchKeywords(keywords: string[]) {
|
private async searchKeywords(keywords: string[]) {
|
||||||
const rawData = await this.getData();
|
const rawData = await this.getData();
|
||||||
let results: pageData[] = [];
|
const results: pageData[] = [];
|
||||||
|
|
||||||
const regex = new RegExp(keywords.filter((v, index, arr) => {
|
const regex = new RegExp(keywords.filter((v, index, arr) => {
|
||||||
arr[index] = escapeRegExp(v);
|
arr[index] = escapeRegExp(v);
|
||||||
return v !== '';
|
return v.trim() !== '';
|
||||||
}).join('|'), 'gi');
|
}).join('|'), 'gi');
|
||||||
|
|
||||||
for (const item of rawData) {
|
for (const item of rawData) {
|
||||||
@ -222,7 +222,7 @@ class Search {
|
|||||||
|
|
||||||
const eventHandler = (e) => {
|
const eventHandler = (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
const keywords = this.input.value;
|
const keywords = this.input.value.trim();
|
||||||
|
|
||||||
Search.updateQueryString(keywords, true);
|
Search.updateQueryString(keywords, true);
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user