参考: Butterfly 安裝文檔(四) 主題配置-2 | Butterfly

安装

  • npm安装依赖

    1
    2
    # https://github.com/LouisBarranqueiro/hexo-algoliasearch
    npm install hexo-algoliasearch --save
  • 主題配置文件启动algolia

    1
    2
    3
    4
    algolia_search:
    enable: true
    hits:
    per_page: 6
  • _config.yml配置信息

    1

Alogolia配置

  • 登陆进入 Algolia 官网,我们可以使用 GitHub 或 Google 帐号登录。然后进入 Dashboard

  • 左侧Products选择 Indices ,新建一个 Index,这里创建了一个名为hexo的索引

  • Index(索引)也就是搜索引擎中的数据库,我们所有的搜索相关信息都存在里面。

配置 API Key

  • 配置 Algolia——API Keys 到我们自己的 hexo 站点中,关联两者,使得 Algolia 能够搜集我们 hexo 站点的数据

  • 点击 Dashborad 左侧的 Settings,进入Team and Access下的Api keys.其中的 Application IDSearch-Only API KeyAdmin API KEY信息将会被用到

  • 首先我们需要修改 hexo 站点根目录下的 _config.yml,进行以下配置:

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    algolia:
    appId: 'XXX'
    apiKey: 'XXX'
    adminApiKey: "XXX"
    chunkSize: 5000
    indexName: 'hexo' # 创建的index名称
    fields:
    - content:strip:truncate,0,500
    - excerpt:strip
    - gallery
    - permalink
    - photos
    - slug
    - tags
    - title
  • 在 hexo 站点根目录下执行hexo clean ; hexo g; hexo algolia 来搜集数据更新到我们刚创建的 Index 中。

  • 不清除现有索引hexo algolia -n, --no-clear

忽略扫描

  • 使用修改的

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    npm install git+https://github.com/fulsun/hexo-algoliasearch.git

    algolia:
    appId: 'XXX'
    apiKey: 'XXX'
    adminApiKey: "XXX"
    chunkSize: 5000
    hidden: 'hidden'
    indexName: 'hexo' # 创建的index名称
    fields:
    - content:strip:truncate,0,500
    - excerpt:strip
    - gallery
    - permalink
    - photos
    - slug
    - tags
    - title


    # 文章配置 hidden: true
    ---
    title: title
    date: 2019-07-20 20:10:15
    tags: tags
    categories: categories
    hidden: true
    ---