LI YAO'S BLOG

有趣的人生, 一半家长里短, 一半山川胡海

Hexo开启本地搜索功能

​ 修改主题配置文件`_config.yml,开启本地搜索功能

1
2
3
4
5
6
7
8
9
10
11
12
13
# Local Search
# Dependencies: https://github.com/theme-next/hexo-generator-searchdb
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: 1
# Unescape html strings to the readable one.
unescape: false
# Preload the search data when the page loads.
preload: false

​ enable 为是否启用本地搜索
​ trigger 选auto则搜索时输入自动出现结果,选manual则搜索时输入完成需手动点击回车或搜索按钮出结果
​ top_n_per_article 显示每篇文章的top n个结果,通过设置为-1显示所有结果
​ unescape 将html字符串转换为可读的字符串
​ preload 在页面加载时预加载搜索数据。

​ 启用此功能需要安装hexo-generator-searchdb,在根目录下使用以下命令安装:

1
npm install hexo-generator-searchdb --save

​ 最后再主题配置文件_config.yml添加如下配置:

1
2
3
4
5
search:
path: search.xml
field: post
format: html
limit: 10000

​ 配置好后,使用hexo g与hexo s命令部署启动查看效果即可

赞赏一杯咖啡