知乎の記事を参考にした。参考記事のほうが詳しいが、食い違うところはこちらの記事を優先してほしい。
https://zhuanlan.zhihu.com/p/35668237
Node.js を入れる
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
sudo npm cache clean -f
sudo npm install -g n
sudo n stableTo upgrade to latest version (and not current stable) version, you can use
sudo n latest- Fix PATH:
sudo apt-get install --reinstall nodejs-legacy # fix /usr/bin/node- To undo:
sudo n rm 6.0.0 # replace number with version of Node that was installed
sudo npm uninstall -g nYou may need to restart your terminal to see the updated node version.
このあとの一部は元記事を見ればよく、ここでは繰り返さない。
Hexo を入れる
公式どおり。
npm install hexo-cli -g
hexo init blog
cd blog
npm install
hexo server手順が失敗したら sudo を足してみてもいいかも。
GitHub とローカルをつなぐ
npm install hexo-deployer-git --savegit config --global user.name "SherlockShemol"
git config --global user.email "shemol@163.com"SSH 鍵を作る
ssh-keygen -t rsa -C "shemol@163.com"cat ~/.ssh/id_rsa.pub出力を枠にコピーし、SSH keys に貼って確定して保存。
ssh -T git@github.com を入力してユーザー名が出れば成功。
ブログのルートにある _config.yml を開く。ブログの設定ファイルで、各種情報を変えられる。
最後の設定を変える:
deploy:
type: git
repository: <https://github.com/SherlockShemol/SherlockShemol.github.io>
branch: masterrepository は自分の GitHub プロジェクトの URL に。
テーマを変える
元ブログを見る。
Even テーマで npm install がエラー
https://sobaigu.com/hexo-renderer-sass-error.html
こうする
npm uninstall hexo-renderer-sass
npm i --save hexo-renderer-sass-next残りはドキュメントを見ればいい。
Hexo のデプロイ問題
GitHub の新ルールで、Hexo からコードを出すには token が必要。
対処:
Settings->Developer settings->Personal access tokens->Personal access tokensで新しいトークンを作るhexo -dのあと、アカウントとパスワードを聞くダイアログが出る。ここに入れるのはパスワードではなく token
参考:https://blog.csdn.net/qq_21040559/article/details/122621179