那么简记一下配置过程吧。

不论如何,请首先参阅 官方文档

我的配置思路是:

  • Run Nginx on the server and set the web root to a directory such as /var/www/blog/.
  • Install Hugo locally.
  • Install rsync on both the local machine and the server.

Hugo 生成静态文件后,通过 rsync 将本地 public/ 目录中的文件同步到服务器的 /var/www/blog/,即可完成网站部署。使用 SSH 的 rsync 命令如下:

1
rsync -avh -e "ssh -i ./key.pem" --delete ./public/ root@host_name_of_your_server:/var/www/blog/

安装

https://github.com/gohugoio/hugo/releases

在大多数 Linux 发行版下安装 Hugo 都非常轻松,我使用过的有:

1
2
sudo apt install hugo
sudo zypper install hugo

皆可一行命令解决问题。至于如何初始化,官方文档所言毕尽。

有时 Debian 软件源中的 Hugo 版本过旧,可以手动安装 .deb 包:

https://github.com/gohugoio/hugo/releases

1
sudo dpkg -i hugo_<version>.deb

如需卸载:

1
sudo dpkg -r hugo

主题

想必没人愿意一直使用官方示例主题。本站使用了 hugo-theme-meme。基本安装方式请参考其 GitHub 页面;config.toml 中也有较为详尽的注释,个性化设置比较轻松。

我遇到的一个意外情况是:在 config.toml 中写入以下配置时,菜单链接并未生效:

1
2
3
4
5
[menu]
    [[menu.main]]
    pageref = "/posts/"
    name = "文章"
    ...

pageref 改为 url 可解决此问题。

更多个性化设置

为了防止更新主题时出现 Git 合并冲突,需要在 Hugo 网站目录(即运行 hugo 命令即可生成静态页面的目录)下新建 layouts/ 目录。其中的修改会覆盖 themes/meme/layouts/ 下的对应文件。

我反对纯白的页面背景,于是为页面添加了背景色——正如您所见。

编辑 layouts/index.htmllayouts/partials/pages/post.html,在其中添加:

1
2
3
4
5
6
7
8
9
<!-- Custom color  -->
<head>
    <style>
        body {
            background-color: #f2e6f4; /* 任何你喜欢的颜色 */
        }
    </style>
</head>
<!-- Custom color -->

即可。

是的,感谢 ChatGPT。

至于服务端的 Nginx 配置,此处不再赘述。

我也未作出更多的修改了。