From 0ebb0c58103c4e095f4ca29ef4ca1ff91c37c28f Mon Sep 17 00:00:00 2001
From: Mimi <1119186082@qq.com>
Date: Wed, 29 Jul 2020 17:05:45 +0800
Subject: [PATCH] Optimize local search (#64)
* Highlight search keywords
* Sort search results by the number of keywords included
---
layout/_partials/search/localsearch.njk | 2 +-
scripts/helpers/next-config.js | 16 +-
.../components/third-party/search.styl | 13 +-
source/js/local-search.js | 343 ++++++++++--------
4 files changed, 211 insertions(+), 163 deletions(-)
diff --git a/layout/_partials/search/localsearch.njk b/layout/_partials/search/localsearch.njk
index df81e95..26931e6 100644
--- a/layout/_partials/search/localsearch.njk
+++ b/layout/_partials/search/localsearch.njk
@@ -3,7 +3,7 @@
-
diff --git a/scripts/helpers/next-config.js b/scripts/helpers/next-config.js
index cef8bea..89d5b9a 100644
--- a/scripts/helpers/next-config.js
+++ b/scripts/helpers/next-config.js
@@ -9,7 +9,6 @@ const { parse } = require('url');
*/
hexo.extend.helper.register('next_config', function() {
const { config, theme, next_version } = this;
- config.algolia = config.algolia || {};
const exportConfig = {
hostname : parse(config.url).hostname || config.url,
root : config.root,
@@ -24,19 +23,22 @@ hexo.extend.helper.register('next_config', function() {
lazyload : theme.lazyload,
pangu : theme.pangu,
comments : theme.comments,
- algolia : {
+ motion : theme.motion,
+ prism : config.prismjs.enable && !config.prismjs.preprocess
+ };
+ if (theme.algolia_search && theme.algolia_search.enable) {
+ config.algolia = config.algolia || {};
+ exportConfig.algolia = {
appID : config.algolia.applicationID,
apiKey : config.algolia.apiKey,
indexName: config.algolia.indexName,
hits : theme.algolia_search.hits,
labels : theme.algolia_search.labels
- },
- localsearch: theme.local_search,
- motion : theme.motion,
- prism : config.prismjs.enable && !config.prismjs.preprocess
- };
+ };
+ }
if (config.search) {
exportConfig.path = config.search.path;
+ exportConfig.localsearch = theme.local_search;
}
return `