mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-18 18:33:42 +00:00
Fix search with Pjax
This commit is contained in:
parent
7129d09d81
commit
eb194a7258
10
source/js/third-party/search/algolia-search.js
vendored
10
source/js/third-party/search/algolia-search.js
vendored
@ -1,4 +1,4 @@
|
||||
/* global instantsearch, algoliasearch, CONFIG */
|
||||
/* global instantsearch, algoliasearch, CONFIG, pjax */
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
const { indexName, appID, apiKey, hits } = CONFIG.algolia;
|
||||
@ -13,9 +13,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
}
|
||||
});
|
||||
|
||||
window.pjax && search.on('render', () => {
|
||||
window.pjax.refresh(document.querySelector('.algolia-hits'));
|
||||
});
|
||||
if (typeof pjax === 'object') {
|
||||
search.on('render', () => {
|
||||
pjax.refresh(document.querySelector('.algolia-hits'));
|
||||
});
|
||||
}
|
||||
|
||||
// Registering Widgets
|
||||
search.addWidgets([
|
||||
|
||||
16
source/js/third-party/search/local-search.js
vendored
16
source/js/third-party/search/local-search.js
vendored
@ -1,4 +1,4 @@
|
||||
/* global CONFIG */
|
||||
/* global CONFIG, pjax */
|
||||
|
||||
document.addEventListener('DOMContentLoaded', () => {
|
||||
if (!CONFIG.path) {
|
||||
@ -192,7 +192,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
container.innerHTML = `<div class="search-stats">${stats}</div>
|
||||
<hr>
|
||||
<ul class="search-result-list">${resultItems.map(result => result.item).join('')}</ul>`;
|
||||
window.pjax && window.pjax.refresh(container);
|
||||
if (typeof pjax === 'object') pjax.refresh(container);
|
||||
}
|
||||
};
|
||||
|
||||
@ -203,13 +203,11 @@ document.addEventListener('DOMContentLoaded', () => {
|
||||
.then(res => {
|
||||
// Get the contents from search data
|
||||
isfetched = true;
|
||||
datas = isXml ? [...new DOMParser().parseFromString(res, 'text/xml').querySelectorAll('entry')].map(element => {
|
||||
return {
|
||||
title : element.querySelector('title').textContent,
|
||||
content: element.querySelector('content').textContent,
|
||||
url : element.querySelector('url').textContent
|
||||
};
|
||||
}) : JSON.parse(res);
|
||||
datas = isXml ? [...new DOMParser().parseFromString(res, 'text/xml').querySelectorAll('entry')].map(element => ({
|
||||
title : element.querySelector('title').textContent,
|
||||
content: element.querySelector('content').textContent,
|
||||
url : element.querySelector('url').textContent
|
||||
})) : JSON.parse(res);
|
||||
// Only match articles with non-empty titles
|
||||
datas = datas.filter(data => data.title).map(data => {
|
||||
data.title = data.title.trim();
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user