hexo的next主题添加本地搜索功能(最新版,解决搜索图标不正常)
阿猿为了加个搜索功能,实在是花费了超多时间。根据网络上的教程,我的搜索功能一部署到服务器就出现了搜索图标不正常显示,然后费劲九牛二虎之力才发现。那些教程只适用于旧版的hexo。
- 摆一个错误的给大家看看,这就是困扰了超久的问题
添加搜索功能的正确姿势
- 我们先来到博客的本地根目录
- 打开git bash 输入以下命令
npm install hexo-generator-searchdb --save
-
然后进入hexo的配置文件(位置:根目录/_config.yml)
-
添加以下代码
# Search Config
search:
path: search.json #之前就是这里出了问题导致图标错误,错误的教程是 search.xml
field: post
format: html
limit: 1000
-
进入主题的根目录(blogjsw\themes\next_config.yml)
-
修改以下代码,把enable的false改为true
# 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
-
然后行云流水的操作一波
hexo c
hexo g
hexo d
- 效果图,我的上帝啊,这是多么好看的搜索功能