最近不知道为什么local_search挂了

https://f004.backblazeb2.com/file/jerspicture/Qexo/2022/12/d3d2c4004c6e9d6ddcfc3d29fe28b3b9.png

没办法修复,而且仔细一看search.xml文件已经超过2M,而我博客才刚刚开头,只好换成algolia。

插件选择

1
2
npm install hexo-algolia --save
npm install hexo-algoliasearch --save

分别是 hexo-algolia 和 hexo-algoliasearch,他们的介绍分别为

Index your hexo website content to Algolia Search.

🔎 A plugin to index posts of your Hexo blog on Algolia

本教程选用hexo-algoliasearch

安装

1
npm install hexo-algoliasearch --save

去主题配置文件打开 Algolia 搜索,记得关闭本地搜索,二者只能取其一。

编辑_config.butterfly.yml :

1
2
3
4
5
6
7
8
9
# Algolia search
algolia_search:
enable: true
hits:
per_page: 3

# Local search
local_search:
enable: false

配置

前往 Algolia 官网注册一个账号,新建 应用和index

获取appId,apiKey,adminApiKey,记住三个变量。

在_config.yml中添加

1
2
3
4
5
6
7
8
9
10
algolia:
appId: "你的appId"
apiKey: "你的apiKey"
adminApiKey: "你的adminApiKey"
indexName: "你说要引用的名字如:Hexo"
chunkSize: 5000
fields:
- path
- title
- content:strip

使用

下面介绍两种上传搜索资料的方法

本地

1
2
3
4
5
6
hexo algolia
而在这之前还需要hexo g生成文件
所以具体使用命令就是
hexo cl && hexo g && hexo algolia
或者在未安装 HEXO CLI 的情况下使用以下命令
npm run clean && npm run build && hexo algolia -n

Github Action

前提是你已经配置好博客源文件的Github Action

在BlogRoot\.github.yml中生成静态文件命令中最后一行添加

1
hexo algolia --no-clear

到这里恭喜你完成Algolia的配置。

有疑问可以评论