mirror of
https://github.com/next-theme/hexo-theme-next.git
synced 2026-01-17 18:22:33 +00:00
Optimize Algolia Search
This commit is contained in:
parent
68654c2985
commit
92bdb32a29
@ -1,3 +1,6 @@
|
|||||||
|
# This file is automatically generated
|
||||||
|
# See https://github.com/next-theme/plugins
|
||||||
|
|
||||||
anime:
|
anime:
|
||||||
name: animejs
|
name: animejs
|
||||||
version: 3.2.0
|
version: 3.2.0
|
||||||
|
|||||||
@ -7,7 +7,7 @@
|
|||||||
<i class="fa fa-times-circle"></i>
|
<i class="fa fa-times-circle"></i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div class="algolia-results">
|
<div class="search-result-container">
|
||||||
<div id="algolia-stats"></div>
|
<div id="algolia-stats"></div>
|
||||||
<div id="algolia-hits"></div>
|
<div id="algolia-hits"></div>
|
||||||
<div id="algolia-pagination"></div>
|
<div id="algolia-pagination"></div>
|
||||||
|
|||||||
@ -11,7 +11,7 @@
|
|||||||
<i class="fa fa-times-circle"></i>
|
<i class="fa fa-times-circle"></i>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
<div id="search-result">
|
<div class="search-result-container">
|
||||||
<div id="no-result">
|
<div id="no-result">
|
||||||
<i class="fa fa-spinner fa-pulse fa-5x"></i>
|
<i class="fa fa-spinner fa-pulse fa-5x"></i>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -53,6 +53,7 @@ const points = {
|
|||||||
]
|
]
|
||||||
};
|
};
|
||||||
|
|
||||||
|
// Required by theme-next-docs
|
||||||
module.exports = {
|
module.exports = {
|
||||||
resolve,
|
resolve,
|
||||||
highlightTheme,
|
highlightTheme,
|
||||||
|
|||||||
@ -71,6 +71,30 @@
|
|||||||
display: none;
|
display: none;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.search-result-container {
|
||||||
|
height: calc(100% - 55px);
|
||||||
|
overflow: auto;
|
||||||
|
padding: 5px 25px;
|
||||||
|
|
||||||
|
hr {
|
||||||
|
margin: 10px 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
.search-result-list {
|
||||||
|
margin: 0 5px;
|
||||||
|
padding: 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
a.search-result-title {
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
|
|
||||||
|
p.search-result {
|
||||||
|
border-bottom: 1px dashed $grey-light;
|
||||||
|
padding: 5px 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (hexo-config('algolia_search.enable')) {
|
if (hexo-config('algolia_search.enable')) {
|
||||||
@ -92,25 +116,6 @@ if (hexo-config('algolia_search.enable')) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
.algolia-results {
|
|
||||||
height: calc(100% - 55px);
|
|
||||||
overflow: auto;
|
|
||||||
padding: 5px 30px;
|
|
||||||
|
|
||||||
hr {
|
|
||||||
margin: 10px 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
.algolia-hit-item {
|
|
||||||
margin: 15px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
.algolia-hit-item-link {
|
|
||||||
border-bottom: 1px dashed $grey-light;
|
|
||||||
display: block;
|
|
||||||
}
|
|
||||||
|
|
||||||
.algolia-pagination {
|
.algolia-pagination {
|
||||||
// Override default style of ul
|
// Override default style of ul
|
||||||
margin: 40px 0;
|
margin: 40px 0;
|
||||||
@ -139,26 +144,12 @@ if (hexo-config('local_search.enable')) {
|
|||||||
padding: 2px;
|
padding: 2px;
|
||||||
}
|
}
|
||||||
|
|
||||||
ul.search-result-list {
|
.search-result-container {
|
||||||
margin: 0 5px;
|
|
||||||
padding: 0;
|
|
||||||
width: 100%;
|
|
||||||
}
|
|
||||||
|
|
||||||
p.search-result {
|
|
||||||
border-bottom: 1px dashed $grey-light;
|
|
||||||
padding: 5px 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
a.search-result-title {
|
|
||||||
font-weight: bold;
|
|
||||||
}
|
|
||||||
|
|
||||||
#search-result {
|
|
||||||
display: flex;
|
display: flex;
|
||||||
height: calc(100% - 55px);
|
}
|
||||||
overflow: auto;
|
|
||||||
padding: 5px 25px;
|
.search-result-list {
|
||||||
|
width: 100%;
|
||||||
}
|
}
|
||||||
|
|
||||||
#no-result {
|
#no-result {
|
||||||
|
|||||||
@ -53,11 +53,19 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}),
|
}),
|
||||||
|
|
||||||
instantsearch.widgets.hits({
|
instantsearch.widgets.hits({
|
||||||
container: '#algolia-hits',
|
container : '#algolia-hits',
|
||||||
templates: {
|
escapeHTML: false,
|
||||||
|
templates : {
|
||||||
item: data => {
|
item: data => {
|
||||||
const link = data.permalink ? data.permalink : CONFIG.root + data.path;
|
const { title, excerpt, excerptStrip, contentStripTruncate } = data._highlightResult;
|
||||||
return `<a href="${link}" class="algolia-hit-item-link">${data._highlightResult.title.value}</a>`;
|
let result = `<a href="${data.permalink}" class="search-result-title">${title.value}</a>`;
|
||||||
|
const content = excerpt || excerptStrip || contentStripTruncate;
|
||||||
|
if (content && content.value) {
|
||||||
|
const div = document.createElement('div');
|
||||||
|
div.innerHTML = content.value;
|
||||||
|
result += `<a href="${data.permalink}"><p class="search-result">${div.textContent.substr(0, 100)}...</p></a>`;
|
||||||
|
}
|
||||||
|
return result;
|
||||||
},
|
},
|
||||||
empty: data => {
|
empty: data => {
|
||||||
return `<div id="algolia-hits-empty">
|
return `<div id="algolia-hits-empty">
|
||||||
@ -66,7 +74,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
cssClasses: {
|
cssClasses: {
|
||||||
item: 'algolia-hit-item'
|
list: 'search-result-list'
|
||||||
}
|
}
|
||||||
}),
|
}),
|
||||||
|
|
||||||
|
|||||||
@ -164,7 +164,7 @@ document.addEventListener('DOMContentLoaded', () => {
|
|||||||
if (!isfetched) return;
|
if (!isfetched) return;
|
||||||
const searchText = input.value.trim().toLowerCase();
|
const searchText = input.value.trim().toLowerCase();
|
||||||
const keywords = searchText.split(/[-\s]+/);
|
const keywords = searchText.split(/[-\s]+/);
|
||||||
const resultContent = document.getElementById('search-result');
|
const resultContent = document.querySelector('.search-result-container');
|
||||||
let resultItems = [];
|
let resultItems = [];
|
||||||
if (searchText.length > 0) {
|
if (searchText.length > 0) {
|
||||||
// Perform local searching
|
// Perform local searching
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user