Hexo is a fast, simple and powerful blog framework. You write posts in Markdown (or other markup languages) and Hexo generates static files with a beautiful theme in seconds.

p.s. 本篇文章環境為 Windows 11 專業版.

預備步驟

  1. 安裝 git.
  2. 安裝 Node.js.
    • 可透過安裝 nvs 來管理多個版本的 Node.js.
      • 法一 - 透過 winget 安裝
      1
      winget install jasongin.nvs
      • 法二 - 透過 choco 安裝
      1
      choco install nvs
      • 或直接從github下載msi安裝程式
    • 運行以下命令
    1
    2
    3
    nvs add latest
    nvs use latest
    nvs link latest
    • 正常的輸出應該是:
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    > nvs add latest
    Downloading [###########################################################################################] 100%
    Extracting [###########################################################################################] 100%
    Added at: $env:LOCALAPPDATA\nvs\node\21.6.1\x64\node.exe
    To use this version now: nvs use node/21.6.1/x64
    > nvs use latest
    PATH -= C:\Program Files\nodejs
    PATH += $env:LOCALAPPDATA\nvs\node\21.6.1\x64
    > nvs link latest
    $env:LOCALAPPDATA\nvs\default -> $env:LOCALAPPDATA\nvs\node\21.6.1\x64
    User profile PATH += $env:LOCALAPPDATA\nvs\default
    • 使用 node -v 來檢驗是否正確安裝Node.js.
    1
    2
    > node -v
    v21.6.1

安裝 Hexo

Install Hexo

Once all the requirements are installed, you can install Hexo with npm:

1
$ npm install -g hexo-cli

Advanced installation and usage

Advanced users may prefer to install and use hexo package instead.

1
$ npm install hexo

Once installed, you can run Hexo in two ways:

1
npx hexo <command>

Linux users can set relative path of node_modules/ folder:

1
echo 'PATH="$PATH:./node_modules/.bin"' >> ~/.profile

then run Hexo using hexo <command>

所以

我選擇直接 npm install -g hexo-cli.

看到 added 54 packages in 8s 就算成功了.

開始開發

使用如下命令初始化你的項目資料夾:

1
2
3
4
5
6
7
8
> E:; cd projects # 切換到 projects 資料夾
> hexo init gang-no-blog
INFO Cloning hexo-starter https://github.com/hexojs/hexo-starter.git
fatal: unable to access 'https://github.com/hexojs/hexo-starter.git/': Recv failure: Connection was reset
WARN git clone failed. Copying data instead
INFO Install dependencies
INFO Start blogging with Hexo!
> cd gang-no-blog

測試一下!!
運行 hexo generate 命令, 然後在VSCode中切換到 public 資料夾, 就可以使用live server預覽生成的博客了.

部署到 GitHub Pages

跟著這篇官方教程走就好👌

結果還是用了One Command

記一下Github的Access Token在這裏生成.

  • 部署命令:hexo clean; hexo deploy