|
1 | 1 | --- |
2 | 2 | title: "Hello, Hugo!" |
3 | 3 | date: 2025-12-22T02:45:19+08:00 |
4 | | -draft: true |
| 4 | +draft: false |
5 | 5 | description: "" |
6 | 6 | showHero: false |
7 | 7 | --- |
8 | 8 |
|
9 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 9 | +启用一个hugo站点所花费的时间比我想象的要久,比wordpress麻烦多了。 |
10 | 10 |
|
11 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 11 | +但是我还是选择了hugo: |
| 12 | +1. 希望通过静态网站减少维护成本,不用天天担心wordpress挂掉了打不开。 |
| 13 | +2. 能更轻松的开始记录,直接用obsidian写了移到hugo就行,而不是在wordpress打开古腾堡编辑器开始纠结排版。 |
| 14 | +3. 准备将go的技能树点亮,用Hugo的同时顺手学一学go。 |
12 | 15 |
|
13 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 16 | +## 准备工作 |
14 | 17 |
|
15 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 18 | +想要运行一个hugo站点,需要下载2-3个程序,分别是hugo、git,如果想作为go模块安装,则还需要安装go语言。因为目前我笔记本用Ubuntu,宿舍台式机用Windows 11,公司的电脑用MacOS,所以我3个系统的方法都会写。默认用bash语言,zsh和powershell重大调整会单独写出来。三个系统的默认包管理器分别是:scoop、brew、apt。 |
16 | 19 |
|
17 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 20 | +### 包管理器 |
18 | 21 |
|
19 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 22 | +Windows安装[scoop](https://scoop.sh) |
20 | 23 |
|
21 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 24 | +```powershell |
| 25 | +Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser |
| 26 | +Invoke-RestMethod -Uri https://get.scoop.sh | Invoke-Expression |
| 27 | +``` |
22 | 28 |
|
23 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 29 | +MacOS安装[brew](https://brew.sh/zh-cn/),运行下面的命令或者[下载pkg安装器](https://github.com/Homebrew/brew/releases/latest)。 |
24 | 30 |
|
25 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 31 | +```bash |
| 32 | +/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)" |
| 33 | +``` |
26 | 34 |
|
27 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
28 | 35 |
|
29 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 36 | +### git |
30 | 37 |
|
31 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 38 | +安装git,可以用安装包或者直接命令行 |
32 | 39 |
|
33 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 40 | +```powershell |
| 41 | +scoop install git |
| 42 | +``` |
34 | 43 |
|
35 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 44 | +```zsh |
| 45 | +brew install git |
| 46 | +``` |
36 | 47 |
|
37 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 48 | +提交代码前要设置一些配置。默认主分支名等等。 |
38 | 49 |
|
39 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 50 | +```bash |
| 51 | +git config --global user.email "teacup418@fp.ac.cn" |
| 52 | +git config --global user.name "Vincent Zhong" |
| 53 | +``` |
40 | 54 |
|
41 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 55 | +### proxy |
42 | 56 |
|
43 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 57 | +设置代理为本地的clash,我的混合端口为`7890`,根据实际情况修改。 |
44 | 58 |
|
45 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 59 | +```bash |
| 60 | +git config --global http.proxy "socks5://127.0.0.1:7890" |
| 61 | +``` |
46 | 62 |
|
47 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 63 | +取消设置代理 |
48 | 64 |
|
49 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 65 | +```bash |
| 66 | +git config --global --unset http.proxy |
| 67 | +``` |
50 | 68 |
|
51 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 69 | +## 安装hugo |
52 | 70 |
|
53 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 71 | +### 命令行安装hugo-entened |
54 | 72 |
|
55 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 73 | +没有特殊理由就直接安装hugo扩展版。 |
56 | 74 |
|
57 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 75 | +```powershell |
| 76 | +scoop install hugo-extended |
| 77 | +``` |
58 | 78 |
|
59 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 79 | +MacOS的hugo已经是扩展版了,直接安装hugo就行。 |
60 | 80 |
|
61 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 81 | +```zsh |
| 82 | +brew install hugo |
| 83 | +``` |
62 | 84 |
|
63 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 85 | +<!-- ```bash |
| 86 | +sudo apt install hugo |
| 87 | +``` --> |
64 | 88 |
|
65 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
66 | 89 |
|
67 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
68 | 90 |
|
69 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 91 | +### 安装主题 |
70 | 92 |
|
71 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 93 | +经过多轮评估,最后精挑细选了一个名叫blowfish的主题,比较符合我的审美,同时文章也配有侧边章节导航栏,可以快速跳转。有其他的例如paper等主题就是因为目录在文字头尾,看一半时不好跳转,所以没有被采用。 |
72 | 94 |
|
73 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 95 | +blowfish支持两种安装方法,因为不太熟悉go语言,所以暂时先添加为git子模块,后面熟悉了再换。在项目根目录允许下面的命令添加子模块。 |
74 | 96 |
|
75 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
76 | | - |
77 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
78 | | - |
79 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
80 | | - |
81 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
82 | | - |
83 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
84 | | - |
85 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
86 | | - |
87 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
88 | | - |
89 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
90 | | - |
91 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
92 | | - |
93 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
94 | | - |
95 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
96 | | - |
97 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
98 | | - |
99 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
100 | | - |
101 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
102 | | - |
103 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
104 | | - |
105 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
106 | | - |
107 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
108 | | - |
109 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
110 | | - |
111 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
112 | | - |
113 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
114 | | - |
115 | | -启用一个hugo站点所花费的时间比我想象的要久。 |
| 97 | +``` |
| 98 | +git submodule add -b main https://github.com/nunocoracao/blowfish.git themes/blowfish |
| 99 | +``` |
| 100 | + |
| 101 | +每次在新电脑拉取仓库后要额外在`/theme/blowfish`目录中单独拉取模块。 |
| 102 | + |
| 103 | +```bash |
| 104 | +git submodule update --init --recursive |
| 105 | +``` |
| 106 | + |
| 107 | +### 修改配置 |
| 108 | + |
| 109 | +将主题下的配置复制到根目录修改 |
| 110 | + |
| 111 | +```bash |
| 112 | +cp -r /theme/blowfish/config/_default/ /config/_default/ |
| 113 | +``` |
| 114 | + |
| 115 | +然后就是漫长的修改过程了。看[blowfish的文档](https://blowfish.page/zh-cn/docs/configuration/)去,不单独写了。 |
| 116 | + |
| 117 | +## 部署 |
| 118 | + |
| 119 | +github pages |
| 120 | + |
| 121 | +### 绑定域名 |
| 122 | +绑定域名`blog.fp.ac.cn`到GitHub pages,由流水线直接构建、部署,我只需要负责写文章、推送提交就行了。 |
| 123 | + |
| 124 | +TODO: 讲解怎么绑定域名。 |
| 125 | + |
| 126 | +### action |
| 127 | + |
| 128 | +在官方的工作流上进行修改,添加git拉取子模块的步骤。 |
| 129 | + |
| 130 | +```yaml |
| 131 | +name: Build and deploy |
| 132 | +on: |
| 133 | + push: |
| 134 | + branches: |
| 135 | + - main |
| 136 | + workflow_dispatch: |
| 137 | +permissions: |
| 138 | + contents: read |
| 139 | + pages: write |
| 140 | + id-token: write |
| 141 | +concurrency: |
| 142 | + group: pages |
| 143 | + cancel-in-progress: false |
| 144 | +defaults: |
| 145 | + run: |
| 146 | + shell: bash |
| 147 | +jobs: |
| 148 | + build: |
| 149 | + runs-on: ubuntu-latest |
| 150 | + env: |
| 151 | + DART_SASS_VERSION: 1.97.1 |
| 152 | + GO_VERSION: 1.25.5 |
| 153 | + HUGO_VERSION: 0.153.1 |
| 154 | + NODE_VERSION: 24.12.0 |
| 155 | + TZ: Europe/Oslo |
| 156 | + steps: |
| 157 | + - name: Checkout |
| 158 | + uses: actions/checkout@v5 |
| 159 | + with: |
| 160 | + submodules: recursive |
| 161 | + fetch-depth: 0 |
| 162 | + - name: Initialize submodules |
| 163 | + run: | |
| 164 | + git submodule update --init --recursive |
| 165 | + - name: Setup Go |
| 166 | + uses: actions/setup-go@v5 |
| 167 | + with: |
| 168 | + go-version: ${{ env.GO_VERSION }} |
| 169 | + cache: false |
| 170 | + - name: Setup Node.js |
| 171 | + uses: actions/setup-node@v4 |
| 172 | + with: |
| 173 | + node-version: ${{ env.NODE_VERSION }} |
| 174 | + - name: Setup Pages |
| 175 | + id: pages |
| 176 | + uses: actions/configure-pages@v5 |
| 177 | + - name: Create directory for user-specific executable files |
| 178 | + run: | |
| 179 | + mkdir -p "${HOME}/.local" |
| 180 | + - name: Install Dart Sass |
| 181 | + run: | |
| 182 | + curl -sLJO "https://github.com/sass/dart-sass/releases/download/${DART_SASS_VERSION}/dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
| 183 | + tar -C "${HOME}/.local" -xf "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
| 184 | + rm "dart-sass-${DART_SASS_VERSION}-linux-x64.tar.gz" |
| 185 | + echo "${HOME}/.local/dart-sass" >> "${GITHUB_PATH}" |
| 186 | + - name: Install Hugo |
| 187 | + run: | |
| 188 | + curl -sLJO "https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz" |
| 189 | + mkdir "${HOME}/.local/hugo" |
| 190 | + tar -C "${HOME}/.local/hugo" -xf "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz" |
| 191 | + rm "hugo_extended_${HUGO_VERSION}_linux-amd64.tar.gz" |
| 192 | + echo "${HOME}/.local/hugo" >> "${GITHUB_PATH}" |
| 193 | + - name: Verify installations |
| 194 | + run: | |
| 195 | + echo "Dart Sass: $(sass --version)" |
| 196 | + echo "Go: $(go version)" |
| 197 | + echo "Hugo: $(hugo version)" |
| 198 | + echo "Node.js: $(node --version)" |
| 199 | + - name: Install Node.js dependencies |
| 200 | + run: | |
| 201 | + [[ -f package-lock.json || -f npm-shrinkwrap.json ]] && npm ci || true |
| 202 | + - name: Configure Git |
| 203 | + run: | |
| 204 | + git config core.quotepath false |
| 205 | + - name: Cache restore |
| 206 | + id: cache-restore |
| 207 | + uses: actions/cache/restore@v4 |
| 208 | + with: |
| 209 | + path: ${{ runner.temp }}/hugo_cache |
| 210 | + key: hugo-${{ github.run_id }} |
| 211 | + restore-keys: |
| 212 | + hugo- |
| 213 | + - name: Build the site |
| 214 | + run: | |
| 215 | + hugo \ |
| 216 | + --gc \ |
| 217 | + --minify \ |
| 218 | + --baseURL "${{ steps.pages.outputs.base_url }}/" \ |
| 219 | + --cacheDir "${{ runner.temp }}/hugo_cache" |
| 220 | + - name: Cache save |
| 221 | + id: cache-save |
| 222 | + uses: actions/cache/save@v4 |
| 223 | + with: |
| 224 | + path: ${{ runner.temp }}/hugo_cache |
| 225 | + key: ${{ steps.cache-restore.outputs.cache-primary-key }} |
| 226 | + - name: Upload artifact |
| 227 | + uses: actions/upload-pages-artifact@v3 |
| 228 | + with: |
| 229 | + path: ./public |
| 230 | + deploy: |
| 231 | + environment: |
| 232 | + name: github-pages |
| 233 | + url: ${{ steps.deployment.outputs.page_url }} |
| 234 | + runs-on: ubuntu-latest |
| 235 | + needs: build |
| 236 | + steps: |
| 237 | + - name: Deploy to GitHub Pages |
| 238 | + id: deployment |
| 239 | + uses: actions/deploy-pages@v4 |
| 240 | +``` |
| 241 | +
|
| 242 | +去部署的地址看看吧。 |
0 commit comments