本文介绍开启 Next 主题站内搜索功能的方法。
安装插件
hexo-generator-searchdb
npm install hexo-generator-searchdb --save
确定插件安装过程中,没有错误,不然生成站点可能会有搜索框显示问题。
添加内容:
# Search
search:
path: ./public/search.xml
field: post
format: html
limit: 10000
修改主题配置文件,开启站内搜索开关:
# 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文件夹,避免显示异常的问题:
hexo clean && hexo g && hexo d
成功后可以搜索站内内容: