fix(search): theme.js error when search is disabled (#310)
This commit is contained in:
2
assets/js/theme.min.js
vendored
2
assets/js/theme.min.js
vendored
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
@@ -10,7 +10,7 @@
|
|||||||
{{- end -}}
|
{{- end -}}
|
||||||
|
|
||||||
{{- $params := .Params | merge .Site.Params.page -}}
|
{{- $params := .Params | merge .Site.Params.page -}}
|
||||||
{{- .Scratch.Set "version" "0.2.4" -}}
|
{{- .Scratch.Set "version" "0.2.5" -}}
|
||||||
|
|
||||||
{{- if eq hugo.Environment "production" -}}
|
{{- if eq hugo.Environment "production" -}}
|
||||||
{{- .Scratch.Set "cdn" .Site.Params.cdn -}}
|
{{- .Scratch.Set "cdn" .Site.Params.cdn -}}
|
||||||
|
|||||||
@@ -94,17 +94,19 @@ class Theme {
|
|||||||
|
|
||||||
initSearch() {
|
initSearch() {
|
||||||
const searchConfig = this.config.search;
|
const searchConfig = this.config.search;
|
||||||
|
const isMobile = this.util.isMobile();
|
||||||
|
if (!searchConfig || isMobile && this._searchMobileOnce || !isMobile && this._searchDesktopOnce) return;
|
||||||
|
|
||||||
if (!searchConfig.maxResultLength) searchConfig.maxResultLength = 10;
|
if (!searchConfig.maxResultLength) searchConfig.maxResultLength = 10;
|
||||||
if (!searchConfig.snippetLength) searchConfig.snippetLength = 50;
|
if (!searchConfig.snippetLength) searchConfig.snippetLength = 50;
|
||||||
if (!searchConfig.highlightTag) searchConfig.highlightTag = 'em';
|
if (!searchConfig.highlightTag) searchConfig.highlightTag = 'em';
|
||||||
const isMobile = this.util.isMobile();
|
|
||||||
if (!searchConfig || isMobile && this._searchMobileOnce || !isMobile && this._searchDesktopOnce) return;
|
const suffix = isMobile ? 'mobile' : 'desktop';
|
||||||
const classSuffix = isMobile ? 'mobile' : 'desktop';
|
const $header = document.getElementById(`header-${suffix}`);
|
||||||
const $header = document.getElementById(`header-${classSuffix}`);
|
const $searchInput = document.getElementById(`search-input-${suffix}`);
|
||||||
const $searchInput = document.getElementById(`search-input-${classSuffix}`);
|
const $searchToggle = document.getElementById(`search-toggle-${suffix}`);
|
||||||
const $searchToggle = document.getElementById(`search-toggle-${classSuffix}`);
|
const $searchLoading = document.getElementById(`search-loading-${suffix}`);
|
||||||
const $searchLoading = document.getElementById(`search-loading-${classSuffix}`);
|
const $searchClear = document.getElementById(`search-clear-${suffix}`);
|
||||||
const $searchClear = document.getElementById(`search-clear-${classSuffix}`);
|
|
||||||
if (isMobile) {
|
if (isMobile) {
|
||||||
this._searchMobileOnce = true;
|
this._searchMobileOnce = true;
|
||||||
$searchInput.addEventListener('focus', () => {
|
$searchInput.addEventListener('focus', () => {
|
||||||
@@ -156,10 +158,10 @@ class Theme {
|
|||||||
}, false);
|
}, false);
|
||||||
|
|
||||||
const initAutosearch = () => {
|
const initAutosearch = () => {
|
||||||
const autosearch = autocomplete(`#search-input-${classSuffix}`, {
|
const autosearch = autocomplete(`#search-input-${suffix}`, {
|
||||||
hint: false,
|
hint: false,
|
||||||
autoselect: true,
|
autoselect: true,
|
||||||
dropdownMenuContainer: `#search-dropdown-${classSuffix}`,
|
dropdownMenuContainer: `#search-dropdown-${suffix}`,
|
||||||
clearOnSelected: true,
|
clearOnSelected: true,
|
||||||
cssClasses: { noPrefix: true },
|
cssClasses: { noPrefix: true },
|
||||||
debug: true,
|
debug: true,
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ name = "LoveIt"
|
|||||||
license = "MIT"
|
license = "MIT"
|
||||||
licenselink = "https://github.com/dillonzq/LoveIt/blob/master/LICENSE"
|
licenselink = "https://github.com/dillonzq/LoveIt/blob/master/LICENSE"
|
||||||
description = "A Clean, Elegant but Advanced Hugo Theme for Hugo."
|
description = "A Clean, Elegant but Advanced Hugo Theme for Hugo."
|
||||||
homepage = "https://hugo-loveit-en.netlify.com"
|
homepage = "https://hugoloveit.com"
|
||||||
tags = [
|
tags = [
|
||||||
"blog",
|
"blog",
|
||||||
"clean",
|
"clean",
|
||||||
|
|||||||
Reference in New Issue
Block a user