安装插件

插件名称为:hexo-generator-search

安装命令如下:

1
npm install hexo-generator-search --save

修改_config.yml

修改主题的_config.yml,修改local_search的enable为true,代表启用本地搜索

1
2
3
4
5
6
7
8
9
10
11
local_search:
enable: true
# If auto, trigger search by changing input.
# If manual, trigger search by pressing enter key or search button.
trigger: auto
# Show top n results per article, show all results by setting to -1
top_n_per_article: 6
# Unescape html strings to the readable one.
unescape: false
# Preload the search data when the page loads.
preload: false

修改根目录的_config.yml

在根目录的_config.yml中添加以下内容

1
2
3
4
5
6
#本地搜索
search:
path: search.xml
field: post
format: html
limit: 10000

重新部署网站后就可以使用本地搜索功能了