本文最后更新于:2024年1月14日 晚上

本文介绍开启 Next 主题站内搜索功能的方法。

安装插件

安装插件hexo-generator-searchdb

1
npm install hexo-generator-searchdb --save

确定插件安装过程中,没有错误,不然生成站点可能会有搜索框显示问题。

修改站点配置文件

添加内容:

1
2
3
4
5
6
# Search 
search:
path: ./public/search.xml
field: post
format: html
limit: 10000

修改主题配置文件

修改主题配置文件,开启站内搜索开关:

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: 7
# Unescape html strings to the readable one.
unescape: false
# Preload the search data when the page loads.
preload: false

生成站点

生成 hexo 站点,建议先清理public文件夹,避免显示异常的问题:

1
hexo clean && hexo g && hexo d

效果

成功后可以搜索站内内容:



文章链接:
https://www.zywvvd.com/notes/hexo/theme/next/16-next-add-search/next-add-search/


“觉得不错的话,给点打赏吧 ୧(๑•̀⌄•́๑)૭”

微信二维码

微信支付

支付宝二维码

支付宝支付

Next -16- 添加搜索功能
https://www.zywvvd.com/notes/hexo/theme/next/16-next-add-search/next-add-search/
作者
Yiwei Zhang
发布于
2020年3月21日
许可协议