Hexo博客skapp主題部署填坑指南


相信大家都很喜歡 hexo skapp 的主題,由於作者采用結巴分詞,加上需要依賴各種各樣的環境

所以可能大家踩過很多坑,也許每個人踩得坑不一樣,這里使用 Docker 容器 centos 來部署,

這樣大家的環境基本上保持一致,遇到坑的匹配率也會提,不用docker也行,直接從1開始閱讀。

主要是對 node 不怎么熟悉,分享一個填坑的有效手段:多看官方文檔,努力啃啃就能解決

 

0. 可選步驟:啟用容器

$ docker run --name blog -itd -p 36963:8080 centos /bin/bash
$ docker attach blog 

 

1. 通過nvm 安裝 node 和 npm

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.34.0/install.sh | bash
$ source ~/.bashrc
$ nvm list-remote
$ nvm install v10.16.0
$ node -v
v10.16.0

 

2. 安裝 hexo-cli

$ npm -g install hexo-cli
$ hexo init blog
$ cd blog 

這里如果是國內,可能會有點慢,發現卡住就Ctrl+C 重來

 

坑1:  如果沒有安裝 git ,直接 hexo init 就會報如下錯誤

INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
WARN git clone failed. Copying data instead
WARN Failed to install dependencies. Please run 'npm install' manually!

 解決,把 git 安裝了, ps: 這里順便安裝 vim

$ yum -y install vim git

裝好后重新 hexo init blog  && cd blog 即可

 

 

3. 安裝 skapp 主題

& cd themes && git clone https://github.com/Mrminfive/hexo-theme-skapp.git

編輯文件../_config.yml ,將 theme 改成  hexo-theme-skapp

 

4. 安裝依賴

npm install --save \
    hexo-autoprefixer \
    hexo-filter-cleanup \
    hexo-generator-feed \
    hexo-generator-sitemap \
    hexo-renderer-sass \
    hexo-renderer-swig \
    mamboer/lunr.js \
    moment \
    node-sass \
    object-assign

 

坑2: 這里會有幾個卡頓點,因為國內網絡影響

如下中斷重來,不用擔心的是已經裝好的包不會重新裝的,會接着未裝過的

 

 到下載 sharp 包也是一個卡住點,同樣中斷重來

 

 

顯示如下圖就安裝好了

 

5. 生成博客

$ hexo g

 

坑3: sharp 庫沒有編譯好
Something went wrong installing the "sharp" module

Cannot find module '../build/Release/sharp.node'

- Remove the "node_modules/sharp" directory, run "npm install" and look for errors
- Consult the installation documentation at https://sharp.pixelplumbing.com/en/stable/install/
- Search for this error at https://github.com/lovell/sharp/issues

根據提示三種解決辦法:


1)  刪除 sharp 然后重新 npm install 安裝一下

$ rm -rf node_modules/sharp
$ npm install

2)  參考官方網址

https://sharp.pixelplumbing.com/en/stable/install/

3)  參考github上的QA

https://github.com/lovell/sharp/issues

 

第一個辦法重裝一次仍然不行

 

第二辦法去官網文檔看看

 

 

官網上說明了環境要求

1. node.js 版本要在 6 以上 

2. python 要2.7

3. gcc 要 4.8 以上

結果發現我沒有裝gcc ,安裝一下

$ yum -y install gcc gcc-c++

 然后重新安裝一下sharp

$ rm -rf node_modules/sharp/
$ npm install --save sharp

 

 

另外大家可能會遇到其他問題

坑4: node-gyp 或者 libvips 沒裝好

$ npm install node-gyp -g
$ npm install libvips -g

單獨全局重新裝一下,一般確保 which make 存在,python版本為27 基本上都能裝上去

再不行可能是系統發行版支持性問題,下面是官方列出支持的發行版

  • Debian 7+
  • Ubuntu 14.04+
  • Centos 7+
  • Alpine 3.8+ (Node 8+)
  • Fedora
  • openSUSE 13.2+
  • Archlinux
  • Raspbian Jessie
  • Amazon Linux
  • Solus

 

坑5: 缺少nodejieba 也就是結巴分詞庫

突然發現貌似主題作者也沒有給出nodejieba安裝的命令

ERROR Script load failed: themes/hexo-theme-skapp/scripts/renderer.js
Error: Cannot find module '/root/blog/node_modules/nodejieba/build/Release/nodejieba.node'

 

單獨安裝一下,不過不要轉到全局,裝到當前即可,nodejieba 和 sharp 一樣需要 node-gyp 編譯

$ npm install nodejieba --save

 

坑6: 缺少make,gyp編譯不起來

gyp ERR! build error
gyp ERR! stack Error: not found: make

安裝一下編譯工具即可

$ yum -y install make automake

然后重新安裝一下 nodejieba 結巴分詞

$ npm install nodejieba --save

裝好后重新 hexo clean && hexo g

 

 

坑7: 缺少 optipng-bin 

FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: spawn /root/blog/node_modules/optipng-bin/vendor/optipng ENOENT

 

第一時間沒想到是缺少文件,只靠到對方扔了一個URL過來 http://hexo.io/docs/troubleshooting.html

然后是上面的錯誤碼是 ENOENT ,看了hexo官網問題文檔才知道這個錯誤碼表示缺少文件

 

說白點就是 opting-bin 沒有裝,這里安裝一下

$ npm install --save optipng-bin

 

 

6. 曙光

然后重新生成博客

hexo clean && hexo g

 

這回終於生成好了

 

相信大家也遇到不少坑,windows的我也安裝過,也省事不了哪里去,需要額外安裝 MSVC 和 Python27 來編譯 node-gyp

$ npm install -g windows-build-tools
$ npm install -g node-gyp

 

如遇到問題本文仍然解決不了,歡迎在評論區留言,把大家遇到的問題解決方法也添加到本文上去,方便新玩家快速填坑

 

7. 其他的坑

坑8: 缺少jpegtran-bin

FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: spawn /root/blog/node_modules/jpegtran-bin/vendor/jpegtran ENOENT

解決:

$ npm install --save jpegtran-bin

 

坑9: 運行 hexo clean && hexo g 出現解析錯誤

FATAL Something's wrong. Maybe you can find the solution here: http://hexo.io/docs/troubleshooting.html
Error: Parse Error: <a href="https://stackoverflow.com/questions/47018914/cordova-android-emulation-err

說實話這鍋真得讓寫markdown 文檔得背,寫文章出現了特殊符號使得 Markdown 解析器無法解析,比如

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM