hexo的next主题添加搜索功能

3 篇文章 0 订阅

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

  • 修改以下代码,把enablefalse改为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
  • 效果图,我的上帝啊,这是多么好看的搜索功能

image-20200705164244025

  • 7
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 7
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 7
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

杂货店的阿猿

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值