diff --git a/scripts/events/lib/utils.js b/scripts/events/lib/utils.js
index e34613c..8522135 100644
--- a/scripts/events/lib/utils.js
+++ b/scripts/events/lib/utils.js
@@ -53,6 +53,7 @@ const points = {
]
};
+// Required by theme-next-docs
module.exports = {
resolve,
highlightTheme,
diff --git a/source/css/_common/components/third-party/search.styl b/source/css/_common/components/third-party/search.styl
index 0673cbb..435a46a 100644
--- a/source/css/_common/components/third-party/search.styl
+++ b/source/css/_common/components/third-party/search.styl
@@ -71,6 +71,30 @@
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')) {
@@ -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 {
// Override default style of ul
margin: 40px 0;
@@ -139,26 +144,12 @@ if (hexo-config('local_search.enable')) {
padding: 2px;
}
- ul.search-result-list {
- 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 {
+ .search-result-container {
display: flex;
- height: calc(100% - 55px);
- overflow: auto;
- padding: 5px 25px;
+ }
+
+ .search-result-list {
+ width: 100%;
}
#no-result {
diff --git a/source/js/algolia-search.js b/source/js/algolia-search.js
index 9ad8151..630bad0 100644
--- a/source/js/algolia-search.js
+++ b/source/js/algolia-search.js
@@ -53,11 +53,19 @@ document.addEventListener('DOMContentLoaded', () => {
}),
instantsearch.widgets.hits({
- container: '#algolia-hits',
- templates: {
+ container : '#algolia-hits',
+ escapeHTML: false,
+ templates : {
item: data => {
- const link = data.permalink ? data.permalink : CONFIG.root + data.path;
- return `
${data._highlightResult.title.value}`;
+ const { title, excerpt, excerptStrip, contentStripTruncate } = data._highlightResult;
+ let result = `
${title.value}`;
+ const content = excerpt || excerptStrip || contentStripTruncate;
+ if (content && content.value) {
+ const div = document.createElement('div');
+ div.innerHTML = content.value;
+ result += `
${div.textContent.substr(0, 100)}...
`;
+ }
+ return result;
},
empty: data => {
return `
@@ -66,7 +74,7 @@ document.addEventListener('DOMContentLoaded', () => {
}
},
cssClasses: {
- item: 'algolia-hit-item'
+ list: 'search-result-list'
}
}),
diff --git a/source/js/local-search.js b/source/js/local-search.js
index cb0efde..d47dc9e 100644
--- a/source/js/local-search.js
+++ b/source/js/local-search.js
@@ -164,7 +164,7 @@ document.addEventListener('DOMContentLoaded', () => {
if (!isfetched) return;
const searchText = input.value.trim().toLowerCase();
const keywords = searchText.split(/[-\s]+/);
- const resultContent = document.getElementById('search-result');
+ const resultContent = document.querySelector('.search-result-container');
let resultItems = [];
if (searchText.length > 0) {
// Perform local searching