Hexo 博客优化(1)

Hexo 博客的优化提升

Hexo 博客优化(1)

简化发布流程

  • 00 利用 zsh 的 alias 功能简化发布流程
    • 命令行输入zshrc , 添加相应 alias

      1
      2
      3
      alias hn="cd ~/Documents/github.nibirong.com/myblog/source/_posts; subl draft.md"
      alias hp="hexo clean;hexo g;hexo s;hexo server"
      alias hd="hexo clean;hexo d -g"
    • 因此基本博客流程为

      • hn-> new 创建新文章,开始撰写
      • hp-> publish 本地检查渲染效果排版,错字...
      • hd-> delay 部署到远程服务器

提升加载速度

  • 01 取消 google font 服务,加快网页的加载速度
    • myblg >> themes >> next(当前主题) >> _config.ymy

      1
      2
      font:
      enable: false
    • O 加载速度确实快了不少,感谢大妈!

简化 URL

  • 02 重置 url 形式

  • :Year/:Mouth/:Day/:title=>:title

    • 因为习惯在文章命名时添加创建日期,所以取消原先 url 的日期路径显示
    • URL 表达更清晰简洁,无冗余
    • 晤... 不过浏览统计清零了... 莫名心痛...

优化本站搜索功能

  • X 尝试使用本地搜索,发现使用失败
  • 第三方服务集成 - NexT 使用文档
    • 使用 github/google 账户注册
      • 创建一个新的 Index
      • 获取
        • ApplicationID
        • Search-Only API Key
        • Admin API Key
          • 保密信息,需保存到 _config.private.yml
    • 站点目录下安装
      • npm install --save hexo-algolia
      • 但是运行hexo algolia 报错
        • O 报错解决
        • X 仍有遗留问题,搜索不完全
        • 放弃该服务
  • E hexo algolia 报错排查

  • E01 error at AlgoliaSearchNodeJS/Async._drainQueues

    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
    ➜  myblog git:(master) ✗ hexo algolia
    INFO Start processing
    INFO [Algolia] Identified 0 posts to index.
    FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
    Error
    at AlgoliaSearchNodeJS.AlgoliaSearchCore (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/algoliasearch/src/AlgoliaSearchCore.js:54:11)
    at AlgoliaSearchNodeJS.AlgoliaSearch (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/algoliasearch/src/AlgoliaSearch.js:11:21)
    at AlgoliaSearchNodeJS.AlgoliaSearchServer (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/algoliasearch/src/server/builds/AlgoliaSearchServer.js:17:17)
    at new AlgoliaSearchNodeJS (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/algoliasearch/src/server/builds/node.js:79:23)
    at algoliasearch (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/algoliasearch/src/server/builds/node.js:68:10)
    at Hexo.<anonymous> (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/hexo-algolia/lib/command.js:68:22)
    at emitNone (events.js:86:13)
    at Hexo.emit (events.js:185:7)
    at execFilter.then.map.then (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/hexo/lib/hexo/index.js:404:12)
    at tryCatcher (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/util.js:16:23)
    at Promise._settlePromiseFromHandler (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/promise.js:512:31)
    at Promise._settlePromise (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/promise.js:569:18)
    at Promise._settlePromise0 (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/promise.js:693:18)
    at Promise._fulfill (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/promise.js:638:18)
    at MappingPromiseArray.PromiseArray._resolve (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/promise_array.js:126:19)
    at MappingPromiseArray._promiseFulfilled (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/map.js:101:18)
    at Promise._settlePromise (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/promise.js:574:26)
    at Promise._settlePromise0 (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/promise.js:614:10)
    at Promise._settlePromises (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/promise.js:693:18)
    at Async._drainQueue (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/async.js:133:16)
    at Async._drainQueues (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/bluebird/js/release/async.js:143:10)
    • A 搜索:hexo algolia error
    • A 搜索 hexo algolia error at AlgoliaSearchNodeJS.AlgoliaSearchCore at Async._drainQueues
      • => hexo algolia失败 · Issue #1710 · iissnan/hexo-theme-next
        • I 在 algolia 的 dashboard 里重新创建了一个 API,按照说明文档增加了四个权限。 在站点配置文件 algolia 的设置里,把 adminApiKey 这一栏填入新建 API,而不是原来 API 的 admin KEY。然后$ export HEXO_ALGOLIA_INDEXING_KEY = 此 API 的名字,之后就可以成功 hexo algolia 了。
        • A 依照提示进行设置,测试:
          • hexo clean
          • hexo g
          • hexo algolia
        • O 成功运行
        • X 激发 E02
  • E02 INFO [Algolia] Identified 0 posts to index.

  • E03 error

    1
    2
    3
    Error
    at success (/Users/NBR-hugh/Documents/github.nibirong.com/myblog/node_modules/algoliasearch/src/AlgoliaSearchCore.js:375:32)
    at process._tickCallback (internal/process/next_tick.js:103:7)
  • 更换搜索 local search

    • 项目根目录下载 npm install hexo-generator-searchdb --save

    • 项目根目录配置文件_config.yml:

      • 任意位置添加
      1
      2
      3
      4
      # local search
      search:
      path: search.xml
      field: post
    • Theme下的配置文件 _config.yml:

      • 关闭 algolia_search ,启用 local_search
      1
      2
      3
      4
      5
      6
      7
      8
      9
      10
      11
      12
      13
      14
      15
      algolia_search:
      enable: false
      hits:
      per_page: 10
      labels:
      input_placeholder: Search for Posts
      hits_empty: "We didn't find any results for the search: ${query}"
      hits_stats: "${hits} results found in ${time} ms"
      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
  • O 部署成功,搜索测试成功

TL

  • 180802 6T NBR-hugh init
(๑•̀ㅂ•́)و✧