Hexo博客搭建之Next主题添加搜索服务

随着时间的推移,我们博客站点上的文章会越来越多,因此在站点中增加一个文本搜索服务是非常有必要的。本文介绍一种添加站内搜索服务的方法,站点配置基于 Hexo5.4.2 博客和 Next 主题。

Algolia 搜索

NexT 提供 Algolia 搜索插件,搜索你的 Hexo 网站内容。请注意仅在 NexT 配置文件中打开 algolia_search 的 enable 不允许您正确使用 Algolia 搜索。你需要安装相应的 Hexo 插件来索引你的网站。

注册 Algolia 账号,并创建 Index

本地搜索

本地搜索不需要任何外部第三方服务,可以被搜索引擎额外索引。推荐大多数用户使用这种搜索方法。

安装插件

在站点根目录下执行下面的命令:

$ npm install hexo-generator-searchdb

Hexo 配置文件

编辑站点根目录下的 config.yml 配置文件,增加以下内容:

search:
  path: search.xml
  field: post
  content: true
  format: html

Next 配置文件

编辑 Next 主题下的 config.yml 配置文件,启用本地搜索:

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 clean
$ hexo g
$ hexo server

重启完成后,我们可以看到在侧边栏的导航菜单中多出了一项 “搜索” 菜单。

猜你喜欢

转载自blog.csdn.net/zyq55917/article/details/125278500