需要有

  • Node.js
  • Git

安裝Hexo

1
npm install -g hexo-cli

創建部落格

1
2
3
hexo init <folder>
cd <folder>
npm install

創建貼文

1
hexo new "貼文名稱"

創建完後貼文會在source/_post/資料夾中,可以在那裡編輯

1
2
3
4
5
6
7
8
9
10
11
12
---
title: Hexo搭建個人部落格
date: 2024-09-25 19:13:09
---

## 需要有

- Node.js
- Git

## 安裝Hexo
...

建立靜態檔&本機伺服器

1
2
hexo generate
hexo server

本機伺服器預設在localhost:4000

部署

  1. hexo-deployer-git插件:
1
npm install hexo-deployer-git --save
  1. 到Github創建一個repo,名字叫做<username>.github.io(名字很重要)

  2. 然後到_config.yml的最下面:

1
2
3
4
deploy:
type: git
repo: https://github.com/<username>/<username>.github.io.git ## 剛剛的repo
branch: main ## master 也可以
  1. 部署吧老鐵
1
2
hexo clean
hexo deploy

客製化主題

以主題cactus來舉例:

安裝

  1. 在部落格主目錄:

    1
    git clone https://github.com/probberechts/hexo-theme-cactus.git themes/cactus
  2. _config.yml中,把theme改成:

    1
    theme: cactus
  3. 重新創建靜態檔:

    1
    2
    hexo clean
    hexo generate