记得之前多次试着配置过Algolia搜索,都未能成功,今日又试了几次,还是不行。无奈,又去百度了一下,看到了cc的Hexo Butterfly Algolia 搜索的使用一文,跟着配置了一番,结果,意外的成功了,果断记录一下。

准备工作

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

图1

图2

图3

安装插件

对于Algolia搜索,有两个插件,安装方式为:

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

他们的官方介绍为:

  • algolia:Index your hexo website content to Algolia Search.
  • algoliasearch:🔎 A plugin to index posts of your Hexo blog on Algolia

我采用的是hexo-algoliasearch

配置

在站点congif_yml中加入以下配置

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

APPiDapiKeyadminApiKey分别对应上面第三张图中的Application IDSearch-Only API KeyAdmin API Key

indexName为我们创建的index的名字

_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

使用命令

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 && gulp

可选命令

1
2
3
hexo algolia -n
或者
hexo algolia --no-clear

写在结尾

我这次配置完后,运行了一次:

1
hexo algolia -n

然后再部署,发现可以了,但是原来的教程也没有此说法啊,到底是我原来哪里配置有问题,还是确实需要运行一次这个命令呢?哎,谁知道呢?记录到此结束。