跳至文章
Shemol在 Ubuntu(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 key

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 專案地址。

修改主題

看原部落格

我的是 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