From e9f9d0e560f7b8fde091bb8e9b6b860d95146ff6 Mon Sep 17 00:00:00 2001 From: xaoxuu Date: Tue, 29 Nov 2022 21:54:15 +0800 Subject: [PATCH] [opt] search --- _config.yml | 7 +- layout/_partial/sidebar/index.ejs | 2 +- layout/_partial/widgets/search.ejs | 18 ++- scripts/generators/search.js | 180 +++++++++++++++-------------- source/js/search/local-search.js | 25 +--- 5 files changed, 115 insertions(+), 117 deletions(-) diff --git a/_config.yml b/_config.yml index 6b4b047..9ce251e 100755 --- a/_config.yml +++ b/_config.yml @@ -63,10 +63,11 @@ article: search: service: local_search # local_search, todo... - local_search: + local_search: # 在 front-matter 中设置 indexing:false 来避免被搜索索引 field: all # post, page, all - path: /search.json - content: true + path: /search.json # 搜索文件存放位置 + content: true # 是否搜索内容 + codeblock: true # 是否搜索代码块(需要content: true) ######## Comments ######## diff --git a/layout/_partial/sidebar/index.ejs b/layout/_partial/sidebar/index.ejs index 1fd13b2..cbfd48c 100755 --- a/layout/_partial/sidebar/index.ejs +++ b/layout/_partial/sidebar/index.ejs @@ -83,7 +83,7 @@ function layoutWidgets() { if (name in theme.data.widgets) { Object.assign(widget, theme.data.widgets[name]) } - if (typeof w == 'object' && w.override) { + if (typeof w == 'object' && (w.override || w.layout)) { Object.assign(widget, w) } if (widget && widget.layout) { diff --git a/layout/_partial/widgets/search.ejs b/layout/_partial/widgets/search.ejs index 438f5ef..3fbfce4 100644 --- a/layout/_partial/widgets/search.ejs +++ b/layout/_partial/widgets/search.ejs @@ -5,15 +5,23 @@ function layoutDiv() { el += '