mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-18 21:11:19 +02:00
Merge commit '5be51ac3db225d5df501ed1fa1499c41d97dbf65'
This commit is contained in:
@@ -1,3 +1,5 @@
|
||||
import { LRUCache } from '../../helpers';
|
||||
|
||||
const designMode = false;
|
||||
|
||||
const groupByLvl0 = (array) => {
|
||||
@@ -33,10 +35,10 @@ const applyHelperFuncs = (array) => {
|
||||
};
|
||||
|
||||
export const search = (Alpine, cfg) => ({
|
||||
query: designMode ? 'shortcodes' : '',
|
||||
query: designMode ? 'apac' : '',
|
||||
open: designMode,
|
||||
result: {},
|
||||
|
||||
cache: new LRUCache(10), // Small cache, avoids network requests on e.g. backspace.
|
||||
init() {
|
||||
Alpine.bind(this.$root, this.root);
|
||||
|
||||
@@ -66,6 +68,13 @@ export const search = (Alpine, cfg) => ({
|
||||
this.result = {};
|
||||
return;
|
||||
}
|
||||
|
||||
// Check cache first.
|
||||
const cached = this.cache.get(this.query);
|
||||
if (cached) {
|
||||
this.result = cached;
|
||||
return;
|
||||
}
|
||||
var queries = {
|
||||
requests: [
|
||||
{
|
||||
@@ -91,6 +100,7 @@ export const search = (Alpine, cfg) => ({
|
||||
.then((response) => response.json())
|
||||
.then((data) => {
|
||||
this.result = groupByLvl0(applyHelperFuncs(data.results[0].hits));
|
||||
this.cache.put(this.query, this.result);
|
||||
});
|
||||
},
|
||||
root: {
|
||||
@@ -102,7 +112,7 @@ export const search = (Alpine, cfg) => ({
|
||||
['@search-toggle.window']() {
|
||||
this.toggleOpen();
|
||||
},
|
||||
['@keydown.meta.k.window.prevent']() {
|
||||
['@keydown.slash.window.prevent']() {
|
||||
this.toggleOpen();
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user