clean up duplicated search script
This commit is contained in:
parent
2c23acd01e
commit
3b898097d8
|
@ -284,7 +284,7 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
code, pre {
|
code, pre {
|
||||||
padding: 7px;
|
padding: 0.25rem;
|
||||||
line-height: 1.5em;
|
line-height: 1.5em;
|
||||||
font-size: $code-font-size;
|
font-size: $code-font-size;
|
||||||
font-family: $code-font-stack;
|
font-family: $code-font-stack;
|
||||||
|
|
|
@ -49,7 +49,7 @@ $dark: (
|
||||||
content-pre-main-color: #FFA7C4,
|
content-pre-main-color: #FFA7C4,
|
||||||
content-pre-color: #eee,
|
content-pre-color: #eee,
|
||||||
content-pre-number-color: #666,
|
content-pre-number-color: #666,
|
||||||
content-pre-background-color: #1d232f,
|
content-pre-background-color: #171f2e,
|
||||||
content-pre-header-background-color: darken(#011627, 1.5%),
|
content-pre-header-background-color: darken(#011627, 1.5%),
|
||||||
content-pre-border-background-color: #3a3a3a,
|
content-pre-border-background-color: #3a3a3a,
|
||||||
content-pre-header-color: #FCFCFA,
|
content-pre-header-color: #FCFCFA,
|
||||||
|
|
|
@ -14,6 +14,7 @@ enableEmoji = true
|
||||||
paginate = 13
|
paginate = 13
|
||||||
rssLimit = 100
|
rssLimit = 100
|
||||||
|
|
||||||
|
#pygmentsStyle = "monokai"
|
||||||
pygmentsOptions = "linenos=table"
|
pygmentsOptions = "linenos=table"
|
||||||
pygmentsCodefences = true
|
pygmentsCodefences = true
|
||||||
pygmentsUseClasses = true
|
pygmentsUseClasses = true
|
||||||
|
|
|
@ -1,3 +1,10 @@
|
||||||
|
{{ $jquery := resources.Get "js/jquery.min.js" | resources.Fingerprint }}
|
||||||
|
<script defer src="{{ $jquery.RelPermalink }}"></script>
|
||||||
|
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
|
||||||
|
<script defer src="{{ $enquire.RelPermalink }}"></script>
|
||||||
|
{{ $zzo := resources.Get "js/zzo.js" | resources.Minify | resources.Fingerprint }}
|
||||||
|
<script defer src="{{ $zzo.RelPermalink }}"></script>
|
||||||
|
|
||||||
{{ if .Site.Params.custom_js }}
|
{{ if .Site.Params.custom_js }}
|
||||||
{{ range .Site.Params.custom_js }}
|
{{ range .Site.Params.custom_js }}
|
||||||
{{ $custom_template := resources.Get . }}
|
{{ $custom_template := resources.Get . }}
|
||||||
|
@ -7,3 +14,187 @@
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{ end }}
|
{{ end }}
|
||||||
|
|
||||||
|
<script>
|
||||||
|
var runSearch = function() {
|
||||||
|
// search
|
||||||
|
{{ $searchLanguages := .Site.Params.searchLanguages }}
|
||||||
|
var searchLanguages = JSON.parse({{ $searchLanguages | jsonify }});
|
||||||
|
{{ if .Site.IsMultiLingual }}
|
||||||
|
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
||||||
|
{{ else }}
|
||||||
|
var baseurl = "{{.Site.BaseURL}}";
|
||||||
|
{{ end }}
|
||||||
|
|
||||||
|
if (!searchLanguages) {
|
||||||
|
searchLanguages = ['en'];
|
||||||
|
}
|
||||||
|
|
||||||
|
var lunrIndex = null;
|
||||||
|
var pagesIndex = null;
|
||||||
|
var searchResults = null;
|
||||||
|
var searchMenu = null;
|
||||||
|
|
||||||
|
function endsWith(str, suffix) {
|
||||||
|
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
function initLunr() {
|
||||||
|
if (!endsWith(baseurl, "/")) {
|
||||||
|
baseurl = baseurl + '/';
|
||||||
|
};
|
||||||
|
|
||||||
|
$.getJSON(baseurl + "index.json")
|
||||||
|
.done(function (index) {
|
||||||
|
pagesIndex = index;
|
||||||
|
lunrIndex = lunr(function () {
|
||||||
|
this.use(lunr.multiLanguage(...searchLanguages));
|
||||||
|
this.ref('uri');
|
||||||
|
this.field('title');
|
||||||
|
this.field('description');
|
||||||
|
this.field('content');
|
||||||
|
//this.field('tags');
|
||||||
|
//this.field('series');
|
||||||
|
//this.field('categories');
|
||||||
|
|
||||||
|
var that = this;
|
||||||
|
index.forEach(function (page) {
|
||||||
|
that.add(page);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.fail(function (jqxhr, textStatus, error) {
|
||||||
|
var err = textStatus + ", " + error;
|
||||||
|
console.error("Error getting Hugo index file:", err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function search(query) {
|
||||||
|
return lunrIndex.search(query).map(function (result) {
|
||||||
|
return pagesIndex.filter(function (page) {
|
||||||
|
return page.uri === result.ref;
|
||||||
|
})[0];
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSearchResults(results) {
|
||||||
|
searchResults = document.getElementById('search-results');
|
||||||
|
searchMenu = document.getElementById('search-menu');
|
||||||
|
searchResults.setAttribute('class', 'dropdown is-active');
|
||||||
|
|
||||||
|
var content = document.createElement('div');
|
||||||
|
content.setAttribute('class', 'dropdown-content search-content');
|
||||||
|
|
||||||
|
if (results.length > 0) {
|
||||||
|
results.forEach(function (result) {
|
||||||
|
var item = document.createElement('a');
|
||||||
|
item.setAttribute('href', result.uri);
|
||||||
|
item.setAttribute('class', 'dropdown-item');
|
||||||
|
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">📄 ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
||||||
|
content.appendChild(item);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var item = document.createElement('span');
|
||||||
|
item.setAttribute('class', 'dropdown-item');
|
||||||
|
item.innerText = 'No results found';
|
||||||
|
content.appendChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
while (searchMenu.hasChildNodes()) {
|
||||||
|
searchMenu.removeChild(
|
||||||
|
searchMenu.lastChild
|
||||||
|
);
|
||||||
|
}
|
||||||
|
searchMenu.appendChild(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
function renderSearchResultsMobile(results) {
|
||||||
|
searchResults = document.getElementById('search-mobile-results');
|
||||||
|
|
||||||
|
var content = document.createElement('div');
|
||||||
|
content.setAttribute('class', 'mobile-search__content');
|
||||||
|
|
||||||
|
if (results.length > 0) {
|
||||||
|
results.forEach(function (result) {
|
||||||
|
var item = document.createElement('a');
|
||||||
|
item.setAttribute('href', result.uri);
|
||||||
|
item.innerHTML = `<div class="mobile-search__item"><div class="mobile-search__item--title">📄 ${result.title}</div><div class="mobile-search__item--desc">${result.description ? result.description : result.content}</div></div>`;
|
||||||
|
content.appendChild(item);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
var item = document.createElement('span');
|
||||||
|
content.appendChild(item);
|
||||||
|
}
|
||||||
|
|
||||||
|
$('#search-mobile-results').empty();
|
||||||
|
searchResults.appendChild(content);
|
||||||
|
}
|
||||||
|
|
||||||
|
initLunr();
|
||||||
|
|
||||||
|
$("#search").on('input', function (e) {
|
||||||
|
if (!e.target.value) {
|
||||||
|
$('#search-results').attr('class', 'dropdown');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ($(window).width() < 770) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var results = search(e.target.value);
|
||||||
|
renderSearchResults(results);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#search').on('blur', function () {
|
||||||
|
if ($(window).width() < 770) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
setTimeout(function () {
|
||||||
|
$('#search-results').attr('class', 'dropdown');
|
||||||
|
}, 100);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#search').on('click', function (e) {
|
||||||
|
if ($(window).width() < 770) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
if (!e.target.value) {
|
||||||
|
$('#search-results').attr('class', 'dropdown');
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var results = search(e.target.value);
|
||||||
|
renderSearchResults(results);
|
||||||
|
});
|
||||||
|
|
||||||
|
$('#search').on('keydown', function (e) {
|
||||||
|
if ($(window).width() < 770) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
var items = $('#search-menu .dropdown-item');
|
||||||
|
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
||||||
|
|
||||||
|
items.removeClass('is-active');
|
||||||
|
if (e.key === 'ArrowDown') {
|
||||||
|
items.eq(activeIndex + 1).addClass('is-active');
|
||||||
|
} else if (e.key === 'ArrowUp') {
|
||||||
|
items.eq(activeIndex - 1).addClass('is-active');
|
||||||
|
} else if (e.key === 'Enter') {
|
||||||
|
var currentItemLink = items.eq(activeIndex).attr('href');
|
||||||
|
if (currentItemLink) {
|
||||||
|
location.href = currentItemLink;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$("#search-mobile").on('input', function(e) {
|
||||||
|
if (!e.target.value) {
|
||||||
|
$('#search-mobile-results').empty();
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
var results = search(e.target.value);
|
||||||
|
renderSearchResultsMobile(results);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
</script>
|
|
@ -7,184 +7,6 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
// search
|
runSearch();
|
||||||
{{ $searchLanguages := .Site.Params.searchLanguages }}
|
|
||||||
var searchLanguages = JSON.parse({{ $searchLanguages | jsonify }});
|
|
||||||
{{ if .Site.IsMultiLingual }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
|
||||||
{{ else }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}";
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
if (!searchLanguages) {
|
|
||||||
searchLanguages = ['en'];
|
|
||||||
}
|
|
||||||
|
|
||||||
var lunrIndex = null;
|
|
||||||
var pagesIndex = null;
|
|
||||||
var searchResults = null;
|
|
||||||
var searchMenu = null;
|
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initLunr() {
|
|
||||||
if (!endsWith(baseurl, "/")) {
|
|
||||||
baseurl = baseurl + '/';
|
|
||||||
};
|
|
||||||
|
|
||||||
$.getJSON(baseurl + "index.json")
|
|
||||||
.done(function (index) {
|
|
||||||
pagesIndex = index;
|
|
||||||
lunrIndex = lunr(function () {
|
|
||||||
this.use(lunr.multiLanguage(...searchLanguages));
|
|
||||||
this.ref('uri');
|
|
||||||
this.field('title');
|
|
||||||
this.field('description');
|
|
||||||
this.field('content');
|
|
||||||
//this.field('tags');
|
|
||||||
//this.field('series');
|
|
||||||
//this.field('categories');
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
index.forEach(function (page) {
|
|
||||||
that.add(page);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.fail(function (jqxhr, textStatus, error) {
|
|
||||||
var err = textStatus + ", " + error;
|
|
||||||
console.error("Error getting Hugo index file:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function search(query) {
|
|
||||||
return lunrIndex.search(query).map(function (result) {
|
|
||||||
return pagesIndex.filter(function (page) {
|
|
||||||
return page.uri === result.ref;
|
|
||||||
})[0];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResults(results) {
|
|
||||||
searchResults = document.getElementById('search-results');
|
|
||||||
searchMenu = document.getElementById('search-menu');
|
|
||||||
searchResults.setAttribute('class', 'dropdown is-active');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'dropdown-content search-content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">📄 ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerText = 'No results found';
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (searchMenu.hasChildNodes()) {
|
|
||||||
searchMenu.removeChild(
|
|
||||||
searchMenu.lastChild
|
|
||||||
);
|
|
||||||
}
|
|
||||||
searchMenu.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResultsMobile(results) {
|
|
||||||
searchResults = document.getElementById('search-mobile-results');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'mobile-search__content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.innerHTML = `<div class="mobile-search__item"><div class="mobile-search__item--title">📄 ${result.title}</div><div class="mobile-search__item--desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
searchResults.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
initLunr();
|
|
||||||
|
|
||||||
$("#search").on('input', function (e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('blur', function () {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
setTimeout(function () {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('click', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('keydown', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var items = $('#search-menu .dropdown-item');
|
|
||||||
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
|
||||||
|
|
||||||
items.removeClass('is-active');
|
|
||||||
if (e.key === 'ArrowDown') {
|
|
||||||
items.eq(activeIndex + 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'ArrowUp') {
|
|
||||||
items.eq(activeIndex - 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
var currentItemLink = items.eq(activeIndex).attr('href');
|
|
||||||
if (currentItemLink) {
|
|
||||||
location.href = currentItemLink;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#search-mobile").on('input', function(e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResultsMobile(results);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -7,184 +7,6 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
// search
|
runSearch();
|
||||||
{{ $searchLanguages := .Site.Params.searchLanguages }}
|
|
||||||
var searchLanguages = JSON.parse({{ $searchLanguages | jsonify }});
|
|
||||||
{{ if .Site.IsMultiLingual }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
|
||||||
{{ else }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}";
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
if (!searchLanguages) {
|
|
||||||
searchLanguages = ['en'];
|
|
||||||
}
|
|
||||||
|
|
||||||
var lunrIndex = null;
|
|
||||||
var pagesIndex = null;
|
|
||||||
var searchResults = null;
|
|
||||||
var searchMenu = null;
|
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initLunr() {
|
|
||||||
if (!endsWith(baseurl, "/")) {
|
|
||||||
baseurl = baseurl + '/';
|
|
||||||
};
|
|
||||||
|
|
||||||
$.getJSON(baseurl + "index.json")
|
|
||||||
.done(function (index) {
|
|
||||||
pagesIndex = index;
|
|
||||||
lunrIndex = lunr(function () {
|
|
||||||
this.use(lunr.multiLanguage(...searchLanguages));
|
|
||||||
this.ref('uri');
|
|
||||||
this.field('title');
|
|
||||||
this.field('description');
|
|
||||||
this.field('content');
|
|
||||||
//this.field('tags');
|
|
||||||
//this.field('series');
|
|
||||||
//this.field('categories');
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
index.forEach(function (page) {
|
|
||||||
that.add(page);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.fail(function (jqxhr, textStatus, error) {
|
|
||||||
var err = textStatus + ", " + error;
|
|
||||||
console.error("Error getting Hugo index file:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function search(query) {
|
|
||||||
return lunrIndex.search(query).map(function (result) {
|
|
||||||
return pagesIndex.filter(function (page) {
|
|
||||||
return page.uri === result.ref;
|
|
||||||
})[0];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResults(results) {
|
|
||||||
searchResults = document.getElementById('search-results');
|
|
||||||
searchMenu = document.getElementById('search-menu');
|
|
||||||
searchResults.setAttribute('class', 'dropdown is-active');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'dropdown-content search-content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">📄 ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerText = 'No results found';
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (searchMenu.hasChildNodes()) {
|
|
||||||
searchMenu.removeChild(
|
|
||||||
searchMenu.lastChild
|
|
||||||
);
|
|
||||||
}
|
|
||||||
searchMenu.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResultsMobile(results) {
|
|
||||||
searchResults = document.getElementById('search-mobile-results');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'mobile-search__content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.innerHTML = `<div class="mobile-search__item"><div class="mobile-search__item--title">📄 ${result.title}</div><div class="mobile-search__item--desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
searchResults.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
initLunr();
|
|
||||||
|
|
||||||
$("#search").on('input', function (e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('blur', function () {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
setTimeout(function () {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('click', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('keydown', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var items = $('#search-menu .dropdown-item');
|
|
||||||
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
|
||||||
|
|
||||||
items.removeClass('is-active');
|
|
||||||
if (e.key === 'ArrowDown') {
|
|
||||||
items.eq(activeIndex + 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'ArrowUp') {
|
|
||||||
items.eq(activeIndex - 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
var currentItemLink = items.eq(activeIndex).attr('href');
|
|
||||||
if (currentItemLink) {
|
|
||||||
location.href = currentItemLink;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#search-mobile").on('input', function(e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResultsMobile(results);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -19,6 +19,9 @@
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
|
// search
|
||||||
|
runSearch();
|
||||||
|
|
||||||
// masonry
|
// masonry
|
||||||
var $grid = $('.grid').masonry({
|
var $grid = $('.grid').masonry({
|
||||||
itemSelector: '.grid-item',
|
itemSelector: '.grid-item',
|
||||||
|
@ -143,185 +146,5 @@
|
||||||
})
|
})
|
||||||
gallery.init();
|
gallery.init();
|
||||||
}
|
}
|
||||||
|
|
||||||
// search
|
|
||||||
{{ $searchLanguages := .Site.Params.searchLanguages }}
|
|
||||||
var searchLanguages = JSON.parse({{ $searchLanguages | jsonify }});
|
|
||||||
{{ if .Site.IsMultiLingual }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
|
||||||
{{ else }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}";
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
if (!searchLanguages) {
|
|
||||||
searchLanguages = ['en'];
|
|
||||||
}
|
|
||||||
|
|
||||||
var lunrIndex = null;
|
|
||||||
var pagesIndex = null;
|
|
||||||
var searchResults = null;
|
|
||||||
var searchMenu = null;
|
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initLunr() {
|
|
||||||
if (!endsWith(baseurl, "/")) {
|
|
||||||
baseurl = baseurl + '/';
|
|
||||||
};
|
|
||||||
|
|
||||||
$.getJSON(baseurl + "index.json")
|
|
||||||
.done(function (index) {
|
|
||||||
pagesIndex = index;
|
|
||||||
lunrIndex = lunr(function () {
|
|
||||||
this.use(lunr.multiLanguage(...searchLanguages));
|
|
||||||
this.ref('uri');
|
|
||||||
this.field('title');
|
|
||||||
this.field('description');
|
|
||||||
this.field('content');
|
|
||||||
//this.field('tags');
|
|
||||||
//this.field('series');
|
|
||||||
//this.field('categories');
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
index.forEach(function (page) {
|
|
||||||
that.add(page);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.fail(function (jqxhr, textStatus, error) {
|
|
||||||
var err = textStatus + ", " + error;
|
|
||||||
console.error("Error getting Hugo index file:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function search(query) {
|
|
||||||
return lunrIndex.search(query).map(function (result) {
|
|
||||||
return pagesIndex.filter(function (page) {
|
|
||||||
return page.uri === result.ref;
|
|
||||||
})[0];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResults(results) {
|
|
||||||
searchResults = document.getElementById('search-results');
|
|
||||||
searchMenu = document.getElementById('search-menu');
|
|
||||||
searchResults.setAttribute('class', 'dropdown is-active');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'dropdown-content search-content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">📄 ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerText = 'No results found';
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (searchMenu.hasChildNodes()) {
|
|
||||||
searchMenu.removeChild(
|
|
||||||
searchMenu.lastChild
|
|
||||||
);
|
|
||||||
}
|
|
||||||
searchMenu.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResultsMobile(results) {
|
|
||||||
searchResults = document.getElementById('search-mobile-results');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'mobile-search__content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.innerHTML = `<div class="mobile-search__item"><div class="mobile-search__item--title">📄 ${result.title}</div><div class="mobile-search__item--desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
searchResults.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
initLunr();
|
|
||||||
|
|
||||||
$("#search").on('input', function (e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('blur', function () {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
setTimeout(function () {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('click', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('keydown', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var items = $('#search-menu .dropdown-item');
|
|
||||||
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
|
||||||
|
|
||||||
items.removeClass('is-active');
|
|
||||||
if (e.key === 'ArrowDown') {
|
|
||||||
items.eq(activeIndex + 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'ArrowUp') {
|
|
||||||
items.eq(activeIndex - 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
var currentItemLink = items.eq(activeIndex).attr('href');
|
|
||||||
if (currentItemLink) {
|
|
||||||
location.href = currentItemLink;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#search-mobile").on('input', function(e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResultsMobile(results);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -10,183 +10,6 @@
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
// search
|
// search
|
||||||
{{ $searchLanguages := .Site.Params.searchLanguages }}
|
runSearch();
|
||||||
var searchLanguages = JSON.parse({{ $searchLanguages | jsonify }});
|
|
||||||
{{ if .Site.IsMultiLingual }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
|
||||||
{{ else }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}";
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
if (!searchLanguages) {
|
|
||||||
searchLanguages = ['en'];
|
|
||||||
}
|
|
||||||
|
|
||||||
var lunrIndex = null;
|
|
||||||
var pagesIndex = null;
|
|
||||||
var searchResults = null;
|
|
||||||
var searchMenu = null;
|
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initLunr() {
|
|
||||||
if (!endsWith(baseurl, "/")) {
|
|
||||||
baseurl = baseurl + '/';
|
|
||||||
};
|
|
||||||
|
|
||||||
$.getJSON(baseurl + "index.json")
|
|
||||||
.done(function (index) {
|
|
||||||
pagesIndex = index;
|
|
||||||
lunrIndex = lunr(function () {
|
|
||||||
this.use(lunr.multiLanguage(...searchLanguages));
|
|
||||||
this.ref('uri');
|
|
||||||
this.field('title');
|
|
||||||
this.field('description');
|
|
||||||
this.field('content');
|
|
||||||
//this.field('tags');
|
|
||||||
//this.field('series');
|
|
||||||
//this.field('categories');
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
index.forEach(function (page) {
|
|
||||||
that.add(page);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.fail(function (jqxhr, textStatus, error) {
|
|
||||||
var err = textStatus + ", " + error;
|
|
||||||
console.error("Error getting Hugo index file:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function search(query) {
|
|
||||||
return lunrIndex.search(query).map(function (result) {
|
|
||||||
return pagesIndex.filter(function (page) {
|
|
||||||
return page.uri === result.ref;
|
|
||||||
})[0];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResults(results) {
|
|
||||||
searchResults = document.getElementById('search-results');
|
|
||||||
searchMenu = document.getElementById('search-menu');
|
|
||||||
searchResults.setAttribute('class', 'dropdown is-active');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'dropdown-content search-content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">📄 ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerText = 'No results found';
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (searchMenu.hasChildNodes()) {
|
|
||||||
searchMenu.removeChild(
|
|
||||||
searchMenu.lastChild
|
|
||||||
);
|
|
||||||
}
|
|
||||||
searchMenu.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResultsMobile(results) {
|
|
||||||
searchResults = document.getElementById('search-mobile-results');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'mobile-search__content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.innerHTML = `<div class="mobile-search__item"><div class="mobile-search__item--title">📄 ${result.title}</div><div class="mobile-search__item--desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
searchResults.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
initLunr();
|
|
||||||
|
|
||||||
$("#search").on('input', function (e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('blur', function () {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
setTimeout(function () {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('click', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('keydown', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var items = $('#search-menu .dropdown-item');
|
|
||||||
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
|
||||||
|
|
||||||
items.removeClass('is-active');
|
|
||||||
if (e.key === 'ArrowDown') {
|
|
||||||
items.eq(activeIndex + 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'ArrowUp') {
|
|
||||||
items.eq(activeIndex - 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
var currentItemLink = items.eq(activeIndex).attr('href');
|
|
||||||
if (currentItemLink) {
|
|
||||||
location.href = currentItemLink;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#search-mobile").on('input', function(e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResultsMobile(results);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -10,183 +10,6 @@
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
// search
|
// search
|
||||||
{{ $searchLanguages := .Site.Params.searchLanguages }}
|
runSearch();
|
||||||
var searchLanguages = JSON.parse({{ $searchLanguages | jsonify }});
|
|
||||||
{{ if .Site.IsMultiLingual }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
|
||||||
{{ else }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}";
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
if (!searchLanguages) {
|
|
||||||
searchLanguages = ['en'];
|
|
||||||
}
|
|
||||||
|
|
||||||
var lunrIndex = null;
|
|
||||||
var pagesIndex = null;
|
|
||||||
var searchResults = null;
|
|
||||||
var searchMenu = null;
|
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initLunr() {
|
|
||||||
if (!endsWith(baseurl, "/")) {
|
|
||||||
baseurl = baseurl + '/';
|
|
||||||
};
|
|
||||||
|
|
||||||
$.getJSON(baseurl + "index.json")
|
|
||||||
.done(function (index) {
|
|
||||||
pagesIndex = index;
|
|
||||||
lunrIndex = lunr(function () {
|
|
||||||
this.use(lunr.multiLanguage(...searchLanguages));
|
|
||||||
this.ref('uri');
|
|
||||||
this.field('title');
|
|
||||||
this.field('description');
|
|
||||||
this.field('content');
|
|
||||||
//this.field('tags');
|
|
||||||
//this.field('series');
|
|
||||||
//this.field('categories');
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
index.forEach(function (page) {
|
|
||||||
that.add(page);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.fail(function (jqxhr, textStatus, error) {
|
|
||||||
var err = textStatus + ", " + error;
|
|
||||||
console.error("Error getting Hugo index file:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function search(query) {
|
|
||||||
return lunrIndex.search(query).map(function (result) {
|
|
||||||
return pagesIndex.filter(function (page) {
|
|
||||||
return page.uri === result.ref;
|
|
||||||
})[0];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResults(results) {
|
|
||||||
searchResults = document.getElementById('search-results');
|
|
||||||
searchMenu = document.getElementById('search-menu');
|
|
||||||
searchResults.setAttribute('class', 'dropdown is-active');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'dropdown-content search-content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">📄 ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerText = 'No results found';
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (searchMenu.hasChildNodes()) {
|
|
||||||
searchMenu.removeChild(
|
|
||||||
searchMenu.lastChild
|
|
||||||
);
|
|
||||||
}
|
|
||||||
searchMenu.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResultsMobile(results) {
|
|
||||||
searchResults = document.getElementById('search-mobile-results');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'mobile-search__content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.innerHTML = `<div class="mobile-search__item"><div class="mobile-search__item--title">📄 ${result.title}</div><div class="mobile-search__item--desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
searchResults.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
initLunr();
|
|
||||||
|
|
||||||
$("#search").on('input', function (e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('blur', function () {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
setTimeout(function () {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('click', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('keydown', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var items = $('#search-menu .dropdown-item');
|
|
||||||
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
|
||||||
|
|
||||||
items.removeClass('is-active');
|
|
||||||
if (e.key === 'ArrowDown') {
|
|
||||||
items.eq(activeIndex + 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'ArrowUp') {
|
|
||||||
items.eq(activeIndex - 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
var currentItemLink = items.eq(activeIndex).attr('href');
|
|
||||||
if (currentItemLink) {
|
|
||||||
location.href = currentItemLink;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#search-mobile").on('input', function(e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResultsMobile(results);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
|
@ -7,7 +7,7 @@
|
||||||
<script defer src="{{ $clipboard.RelPermalink }}"></script>
|
<script defer src="{{ $clipboard.RelPermalink }}"></script>
|
||||||
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
|
{{ $enquire := resources.Get "js/enquire.min.js" | resources.Fingerprint }}
|
||||||
<script defer src="{{ $enquire.RelPermalink }}"></script>
|
<script defer src="{{ $enquire.RelPermalink }}"></script>
|
||||||
{{ $prism := resources.Get "js/prism.min.js" | resources.Minify | resources.Fingerprint }}
|
{{ $prism := resources.Get "js/prism.min.js" | resources.Fingerprint }}
|
||||||
<script defer src="{{ $prism.RelPermalink }}"></script>
|
<script defer src="{{ $prism.RelPermalink }}"></script>
|
||||||
{{ $zzo := resources.Get "js/zzo.js" | resources.Minify | resources.Fingerprint }}
|
{{ $zzo := resources.Get "js/zzo.js" | resources.Minify | resources.Fingerprint }}
|
||||||
<script defer src="{{ $zzo.RelPermalink }}"></script>
|
<script defer src="{{ $zzo.RelPermalink }}"></script>
|
||||||
|
@ -86,184 +86,7 @@
|
||||||
});
|
});
|
||||||
|
|
||||||
// search
|
// search
|
||||||
{{ $searchLanguages := .Site.Params.searchLanguages }}
|
runSearch();
|
||||||
var searchLanguages = JSON.parse({{ $searchLanguages | jsonify }});
|
|
||||||
{{ if .Site.IsMultiLingual }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
|
||||||
{{ else }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}";
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
if (!searchLanguages) {
|
|
||||||
searchLanguages = ['en'];
|
|
||||||
}
|
|
||||||
|
|
||||||
var lunrIndex = null;
|
|
||||||
var pagesIndex = null;
|
|
||||||
var searchResults = null;
|
|
||||||
var searchMenu = null;
|
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initLunr() {
|
|
||||||
if (!endsWith(baseurl, "/")) {
|
|
||||||
baseurl = baseurl + '/';
|
|
||||||
};
|
|
||||||
|
|
||||||
$.getJSON(baseurl + "index.json")
|
|
||||||
.done(function (index) {
|
|
||||||
pagesIndex = index;
|
|
||||||
lunrIndex = lunr(function () {
|
|
||||||
this.use(lunr.multiLanguage(...searchLanguages));
|
|
||||||
this.ref('uri');
|
|
||||||
this.field('title');
|
|
||||||
this.field('description');
|
|
||||||
this.field('content');
|
|
||||||
//this.field('tags');
|
|
||||||
//this.field('series');
|
|
||||||
//this.field('categories');
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
index.forEach(function (page) {
|
|
||||||
that.add(page);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.fail(function (jqxhr, textStatus, error) {
|
|
||||||
var err = textStatus + ", " + error;
|
|
||||||
console.error("Error getting Hugo index file:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function search(query) {
|
|
||||||
return lunrIndex.search(query).map(function (result) {
|
|
||||||
return pagesIndex.filter(function (page) {
|
|
||||||
return page.uri === result.ref;
|
|
||||||
})[0];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResults(results) {
|
|
||||||
searchResults = document.getElementById('search-results');
|
|
||||||
searchMenu = document.getElementById('search-menu');
|
|
||||||
searchResults.setAttribute('class', 'dropdown is-active');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'dropdown-content search-content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">📄 ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerText = 'No results found';
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (searchMenu.hasChildNodes()) {
|
|
||||||
searchMenu.removeChild(
|
|
||||||
searchMenu.lastChild
|
|
||||||
);
|
|
||||||
}
|
|
||||||
searchMenu.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResultsMobile(results) {
|
|
||||||
searchResults = document.getElementById('search-mobile-results');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'mobile-search__content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.innerHTML = `<div class="mobile-search__item"><div class="mobile-search__item--title">📄 ${result.title}</div><div class="mobile-search__item--desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
searchResults.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
initLunr();
|
|
||||||
|
|
||||||
$("#search").on('input', function (e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('blur', function () {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
setTimeout(function () {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('click', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('keydown', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var items = $('#search-menu .dropdown-item');
|
|
||||||
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
|
||||||
|
|
||||||
items.removeClass('is-active');
|
|
||||||
if (e.key === 'ArrowDown') {
|
|
||||||
items.eq(activeIndex + 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'ArrowUp') {
|
|
||||||
items.eq(activeIndex - 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
var currentItemLink = items.eq(activeIndex).attr('href');
|
|
||||||
if (currentItemLink) {
|
|
||||||
location.href = currentItemLink;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#search-mobile").on('input', function(e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResultsMobile(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
var navbar = $('.navbar');
|
var navbar = $('.navbar');
|
||||||
|
|
||||||
|
|
|
@ -8,183 +8,6 @@
|
||||||
<script>
|
<script>
|
||||||
window.onload = function() {
|
window.onload = function() {
|
||||||
// search
|
// search
|
||||||
{{ $searchLanguages := .Site.Params.searchLanguages }}
|
runSearch();
|
||||||
var searchLanguages = JSON.parse({{ $searchLanguages | jsonify }});
|
|
||||||
{{ if .Site.IsMultiLingual }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}{{.Site.LanguagePrefix}}";
|
|
||||||
{{ else }}
|
|
||||||
var baseurl = "{{.Site.BaseURL}}";
|
|
||||||
{{ end }}
|
|
||||||
|
|
||||||
if (!searchLanguages) {
|
|
||||||
searchLanguages = ['en'];
|
|
||||||
}
|
|
||||||
|
|
||||||
var lunrIndex = null;
|
|
||||||
var pagesIndex = null;
|
|
||||||
var searchResults = null;
|
|
||||||
var searchMenu = null;
|
|
||||||
|
|
||||||
function endsWith(str, suffix) {
|
|
||||||
return str.indexOf(suffix, str.length - suffix.length) !== -1;
|
|
||||||
}
|
|
||||||
|
|
||||||
function initLunr() {
|
|
||||||
if (!endsWith(baseurl, "/")) {
|
|
||||||
baseurl = baseurl + '/';
|
|
||||||
};
|
|
||||||
|
|
||||||
$.getJSON(baseurl + "index.json")
|
|
||||||
.done(function (index) {
|
|
||||||
pagesIndex = index;
|
|
||||||
lunrIndex = lunr(function () {
|
|
||||||
this.use(lunr.multiLanguage(...searchLanguages));
|
|
||||||
this.ref('uri');
|
|
||||||
this.field('title');
|
|
||||||
this.field('description');
|
|
||||||
this.field('content');
|
|
||||||
//this.field('tags');
|
|
||||||
//this.field('series');
|
|
||||||
//this.field('categories');
|
|
||||||
|
|
||||||
var that = this;
|
|
||||||
index.forEach(function (page) {
|
|
||||||
that.add(page);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
})
|
|
||||||
.fail(function (jqxhr, textStatus, error) {
|
|
||||||
var err = textStatus + ", " + error;
|
|
||||||
console.error("Error getting Hugo index file:", err);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function search(query) {
|
|
||||||
return lunrIndex.search(query).map(function (result) {
|
|
||||||
return pagesIndex.filter(function (page) {
|
|
||||||
return page.uri === result.ref;
|
|
||||||
})[0];
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResults(results) {
|
|
||||||
searchResults = document.getElementById('search-results');
|
|
||||||
searchMenu = document.getElementById('search-menu');
|
|
||||||
searchResults.setAttribute('class', 'dropdown is-active');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'dropdown-content search-content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerHTML = `<div class="menu-item"><div class="menu-item__title">📄 ${result.title}</div><div class="menu-item__desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
item.setAttribute('class', 'dropdown-item');
|
|
||||||
item.innerText = 'No results found';
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
while (searchMenu.hasChildNodes()) {
|
|
||||||
searchMenu.removeChild(
|
|
||||||
searchMenu.lastChild
|
|
||||||
);
|
|
||||||
}
|
|
||||||
searchMenu.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
function renderSearchResultsMobile(results) {
|
|
||||||
searchResults = document.getElementById('search-mobile-results');
|
|
||||||
|
|
||||||
var content = document.createElement('div');
|
|
||||||
content.setAttribute('class', 'mobile-search__content');
|
|
||||||
|
|
||||||
if (results.length > 0) {
|
|
||||||
results.forEach(function (result) {
|
|
||||||
var item = document.createElement('a');
|
|
||||||
item.setAttribute('href', result.uri);
|
|
||||||
item.innerHTML = `<div class="mobile-search__item"><div class="mobile-search__item--title">📄 ${result.title}</div><div class="mobile-search__item--desc">${result.description ? result.description : result.content}</div></div>`;
|
|
||||||
content.appendChild(item);
|
|
||||||
});
|
|
||||||
} else {
|
|
||||||
var item = document.createElement('span');
|
|
||||||
content.appendChild(item);
|
|
||||||
}
|
|
||||||
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
searchResults.appendChild(content);
|
|
||||||
}
|
|
||||||
|
|
||||||
initLunr();
|
|
||||||
|
|
||||||
$("#search").on('input', function (e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('blur', function () {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
setTimeout(function () {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
}, 100);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('click', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-results').attr('class', 'dropdown');
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResults(results);
|
|
||||||
});
|
|
||||||
|
|
||||||
$('#search').on('keydown', function (e) {
|
|
||||||
if ($(window).width() < 770) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
var items = $('#search-menu .dropdown-item');
|
|
||||||
var activeIndex = $('#search-menu .dropdown-item.is-active').index();
|
|
||||||
|
|
||||||
items.removeClass('is-active');
|
|
||||||
if (e.key === 'ArrowDown') {
|
|
||||||
items.eq(activeIndex + 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'ArrowUp') {
|
|
||||||
items.eq(activeIndex - 1).addClass('is-active');
|
|
||||||
} else if (e.key === 'Enter') {
|
|
||||||
var currentItemLink = items.eq(activeIndex).attr('href');
|
|
||||||
if (currentItemLink) {
|
|
||||||
location.href = currentItemLink;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
$("#search-mobile").on('input', function(e) {
|
|
||||||
if (!e.target.value) {
|
|
||||||
$('#search-mobile-results').empty();
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
var results = search(e.target.value);
|
|
||||||
renderSearchResultsMobile(results);
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
Loading…
Reference in New Issue