文章へ移動
ShemolUbuntu(Zorin)で Hexo + GitHub ブログを立てる
流程记录

Ubuntu(Zorin)で Hexo + GitHub ブログを立てる

知乎の記事を参考にした。参考記事のほうが詳しいが、食い違うところはこちらの記事を優先してほしい。

https://zhuanlan.zhihu.com/p/35668237

Node.js を入れる

plain text
sudo apt install nodejs

最初からバージョン問題。Ubuntu の版が古すぎる。nodejs は最新に上げるべき。

https://askubuntu.com/questions/426750/how-can-i-update-my-nodejs-to-the-latest-version

Use n module from npm in order to upgrade node

plain text
sudo npm cache clean -f
sudo npm install -g n
sudo n stable

To upgrade to latest version (and not current stable) version, you can use

plain text
sudo n latest
  • Fix PATH:
plain text
sudo apt-get install --reinstall nodejs-legacy     # fix /usr/bin/node
  • To undo:
plain text
sudo n rm 6.0.0     # replace number with version of Node that was installed
sudo npm uninstall -g n

You may need to restart your terminal to see the updated node version.

このあとの一部は元記事を見ればよく、ここでは繰り返さない。

Hexo を入れる

公式どおり。

https://hexo.io/index.html

plain text
npm install hexo-cli -g
hexo init blog
cd blog
npm install
hexo server

手順が失敗したら sudo を足してみてもいいかも。

GitHub とローカルをつなぐ

plain text
npm install hexo-deployer-git --save
shell
git config --global user.name "SherlockShemol"
git config --global user.email "shemol@163.com"

SSH 鍵を作る

shell
ssh-keygen -t rsa -C "shemol@163.com"
shell
cat ~/.ssh/id_rsa.pub

出力を枠にコピーし、SSH keys に貼って確定して保存。

ssh -T git@github.com を入力してユーザー名が出れば成功。

ブログのルートにある _config.yml を開く。ブログの設定ファイルで、各種情報を変えられる。

最後の設定を変える:

shell
deploy:
  type: git
  repository: <https://github.com/SherlockShemol/SherlockShemol.github.io>
  branch: master

repository は自分の GitHub プロジェクトの URL に。

テーマを変える

元ブログを見る。

自分は Even テーマ、GitHub

Even テーマで npm install がエラー

https://sobaigu.com/hexo-renderer-sass-error.html

こうする

plain text
npm uninstall hexo-renderer-sass
npm i --save hexo-renderer-sass-next

残りはドキュメントを見ればいい。

Hexo のデプロイ問題

GitHub の新ルールで、Hexo からコードを出すには token が必要。

対処:

  1. Settings->Developer settings->Personal access tokens->Personal access tokens で新しいトークンを作る
  2. hexo -d のあと、アカウントとパスワードを聞くダイアログが出る。ここに入れるのはパスワードではなく token

参考:https://blog.csdn.net/qq_21040559/article/details/122621179