0%

algolia搜索

好久没打开博客了,某天已看搜索不能用了,重新按照上面的步骤操作,发现流程不太一样了。

一、处理

  1. 尝试命令:hexo algolia,报错
1
2
3
INFO  Validating config
ERROR [hexo-algolia] Please set an `HEXO_ALGOLIA_INDEXING_KEY` environment variable to enable content indexing.
ERROR >> Read https://npmjs.com/hexo-algolia#api-key for more informations.

参考连接进行处理

  1. algolia
  • 注册/登录algolia
  • 创建应用
  • 创建索引
  • 取配置:右上角->Setting->Team and Access->API Keys
    • Application ID
    • Search API Key
    • Write API Key
    • Admin API Key
  1. 项目更改

    • npm install hexo-algoliasearch –save
    • 修改配置文件_config.yml
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    algolia:
    appId: "Z7A3XW4R2I"
    apiKey: "12db1ad54372045549ef465881c17e743"
    adminApiKey: "40321c7c207e7f73b63a19aa24c4761b"
    chunkSize: 5000
    indexName: "my-hexo-blog"
    fields:
    - content:strip:truncate,0,500
    - excerpt:strip
    - gallery
    - permalink
    - photos
    - slug
    - tags
    - title
  2. hexo algolia

二、问题

  1. rm node_modules && npm install –force –verbose,各种报错

    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    npm http fetch GET https://registry.nlark.com/statuses/download/statuses-1.5.0.tgz attempt 3 failed with ECONNRESET
    npm http fetch GET https://registry.nlark.com/urllib/download/urllib-2.11.1.tgz attempt 3 failed with ECONNRESET
    npm http fetch GET https://registry.nlark.com/strip-ansi/download/strip-ansi-6.0.0.tgz attempt 3 failed with ECONNRESET
    npm http fetch GET https://registry.nlark.com/tildify/download/tildify-2.0.0.tgz?cache=0&sync_timestamp=1628772896453&other_urls=https%3A%2F%2Fregistry.nlark.com%2Ftildify%2Fdownload%2Ftildify-2.0.0.tgz attempt 3 failed with ECONNRESET
    npm http fetch GET https://registry.nlark.com/semver/download/semver-6.3.0.tgz attempt 3 failed with ECONNRESET
    npm http fetch GET https://registry.nlark.com/util/download/util-0.10.4.tgz?cache=0&sync_timestamp=1622213272480&other_urls=https%3A%2F%2Fregistry.nlark.com%2Futil%2Fdownload%2Futil-0.10.4.tgz attempt 3 failed with ECONNRESET
    npm http fetch GET https://registry.nlark.com/supports-color/download/supports-color-7.2.0.tgz?cache=0&sync_timestamp=1626703414084&other_urls=https%3A%2F%2Fregistry.nlark.com%2Fsupports-color%2Fdownload%2Fsupports-color-7.2.0.tgz attempt 3 failed with ECONNRESET
    npm http fetch GET https://registry.nlark.com/debug/download/debug-3.1.0.tgz attempt 3 failed with ECONNRESET
    npm http fetch GET https://registry.nlark.com/striptags/download/striptags-3.2.0.tgz attempt 3 failed with ECONNRESET
    npm http fetch GET https://registry.nlark.com/strip-indent/download/strip-indent-3.0.0.tgz attempt 3 failed with ECONNRESET
  2. hexo algolia报错

    • ERROR [hexo-algolia] Please set an HEXO_ALGOLIA_INDEXING_KEY environment variable to enable content indexing.
    • ERROR >> Read https://npmjs.com/hexo-algolia#api-key for more informations.
    • 处理:
      • 方案1:使用git bash执行
      • 方案2:添加环境变量:HEXO_ALGOLIA_INDEXING_KEY adminKey
        • Administrator的用户变量
    • 参考
  3. 页面点击搜索报错:{name: ‘AlgoliaSearchError’, message: ‘Please provide an application ID. Usage: algoliasearch(applicationID, apiKey, opts)’, stack: ‘AlgoliaSearchError: Please provide an application …://liusir.me/js/algolia-search.js?v=7.4.1.js:6:16’}

    • 在主配置_config.yml下加入一下
    1
    2
    plugins:
    - hexo-algoliasearch
    • 还是报错,修改如下再次发布,恢复正常(applicationID)
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    algolia:
    appId: "xxx"
    applicationID: 'xxx'
    apiKey: "eee"
    adminApiKey: "eee"
    chunkSize: 5000
    indexName: "blog"
    fields:
    - content:strip:truncate,0,500
    - excerpt:strip
    - gallery
    - permalink
    - photos
    - slug
    - tags
    - title
    • hexo g -d
    • hexo algolia

二、参考

  1. 参考1
  2. 参考2
  3. 参考3
  4. 参考4
  5. 参考5
  6. 参考6
  7. 参考7
  8. 参考8