Hexo 博客的优化提升
Hexo 博客优化(1)
简化发布流程
- 00 利用 zsh 的 alias 功能简化发布流程
-
命令行输入
zshrc
, 添加相应 alias1
2
3alias 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
2font:
enable: false -
O 加载速度确实快了不少,感谢大妈!
-
简化 URL
-
02 重置 url 形式
-
:Year/:Mouth/:Day/:title
=>:title
- 因为习惯在文章命名时添加创建日期,所以取消原先 url 的日期路径显示
- URL 表达更清晰简洁,无冗余
- 晤... 不过浏览统计清零了... 莫名心痛...
优化本站搜索功能
algolia search
- 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 仍有遗留问题,搜索不完全
- 放弃该服务
- 使用 github/google 账户注册
-
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
- => 执行hexo时的一些报错处理 | LeungGeorge's blog
- I 安装
hexo-algolia@0.2.0
,再执行hexo algolia就可以了
- X 失败
- I 安装
- => 执行hexo时的一些报错处理 | LeungGeorge's blog
- 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
- => hexo algolia失败 · Issue #1710 · iissnan/hexo-theme-next
- A 搜索:
-
E02
INFO [Algolia] Identified 0 posts to index.
- => Algolia search 不會 popup-trigger · Issue #1176 · iissnan/hexo-theme-next
- O 调换操作顺序即可
- hexo clean
- hexo algolia
- hexo g
- X 激发 E03
-
E03 error
1
2
3Error
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)- A 搜索
hexo at success at process._tickCallback
- => hexo deploy · Issue #1503 · hexojs/hexo
- I Change https to ssh
- X 无效
- => hexo deploy · Issue #1503 · hexojs/hexo
- A 搜索
hexo Algolia at success at process._tickCallback
- => 您好!当我集成Algolia时候一直出错——上传不了记录,请问知道如何解决嘛? · Issue #162 · iissnan/theme-next-docs
- I 新建的 API 未添加Index
- X 添加后依旧无效
- => Hexo+Next安装Algolia站内搜索插件 | Porige
- X 修改algolia使用计划
- X 看走眼,错误不同
- => 您好!当我集成Algolia时候一直出错——上传不了记录,请问知道如何解决嘛? · Issue #162 · iissnan/theme-next-docs
- X 没有具体错误信息,尝试多次无果,更换搜索服务
- A 搜索
local search
-
更换搜索 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
15algolia_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