Hugo 主题 PaperMod 配置

为 hugo 站点设置默认主题后,需要在配置文件中对主题进行配置,以定制 hugo 站点显示内容。hugo 配置文件位于站点根目录下,可以是 hugo.toml, hugo.yaml, config.yaml 其中之一。hugo 可选的主题比较丰富,可以在 https://themes.gohugo.io/ 选择自己喜欢的主题。不同的 hugo 主题,对 content 目录下文章组织有不同的要求,并且配置选项也各不相同,配置时还需要参考主题各自的文档。 我的博客配置了 PaperMod 主题,这篇文章主要对该主题的初始配置做一个记录。 1. PaperMod 初始配置 为 hugo 站点下载 PaperMod 主题: # 将 PaperMod 项目设置为 git 仓库的子模块,并下载 PaperMod 主题 git submodule add --depth=1 \ https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod PaperMod 下载到 theme 目录后,将站点默认主题配置为 PaperMod,此时 hugo 配置文件如下: baseURL: "https://examplesite.com/" title: ExampleSite languageCode: 'us-en' theme: PaperMod 这样,hugo 站点已经具备了 PaperMod 主题的雏形,但是站点处于“毛坯”阶段,需要进行一定的“装修”。 注意:hugo 支持本地预览,主题配置过程中可以通过下面的命令实时查看站点“装修”效果: # -D include content marked as draft # --disableFastRender enables full re-renders on changes # --gc enable to run some cleanup tasks (remove unused cache files) after the build hugo server -D --disableFastRender --gc 2. PaperMod 进阶配置 2.1 一些简便的配置 参考 PaperMod 示例站点配置,以下是 hugo 配置文件中一些便利性的配置: ...

March 3, 2026 · 2 min · Carl Cui

基于 Caddy 展示个人静态博客

基于 hugo 生成的个人静态网站,有多种上线方式可以选择(参考 Host and deploy with hugo)。如果你和我一样,打算将个人博客部署在自己的 VPS 服务器上,那么 VPS 服务器需要运行 HTTP 服务,可以是 nginx,也可以是 caddy。这里我选择 caddy,因为它的文档完整,安装配置简单。 1. 安装 caddy caddy 支持多种安装方式,可以直接下载 caddy 二进制文件: from releases on GitHub (expand “Assets”) Refer to Verifying Asset Signatures for how to verify the asset signature from our download page by building from source (either with go or xcaddy) 也可以通过操作系统各自的包管理器进行安装,通常这种方式会为 caddy 自动创建用户和用户组,还会为 caddy 配置 systemd service。 生产环境下,十分建议将 caddy 配置为 systemd service。 Debian, Ubuntu, Raspbian # Debian, Ubuntu, Raspbian sudo apt install -y debian-keyring debian-archive-keyring apt-transport-https curl curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/gpg.key' | sudo gpg --dearmor -o /usr/share/keyrings/caddy-stable-archive-keyring.gpg curl -1sLf 'https://dl.cloudsmith.io/public/caddy/stable/debian.deb.txt' | sudo tee /etc/apt/sources.list.d/caddy-stable.list chmod o+r /usr/share/keyrings/caddy-stable-archive-keyring.gpg chmod o+r /etc/apt/sources.list.d/caddy-stable.list sudo apt update sudo apt install caddy Installing this package automatically starts and runs Caddy as a systemd service named caddy. It also comes with an optional caddy-api service which is not enabled by default, but should be used if you primarily configure Caddy via its API instead of config files. ...

March 2, 2026 · 3 min · Carl Cui

基于 Github Actions 自动更新博客

这篇文章介绍一种将博客自动更新到 HTTP 服务器的方式。 假设你有一个 VPS 服务器,并且上面已经运行 HTTP 服务器(可以是 nginx,也可以是 caddy)。那么将 Hugo 站点提交到 GitHub 后,可以借助 GitHub Actions 将站点自动部署到 VPS 服务器,核心思路是:在 GitHub 的虚拟环境中安装 Hugo、生成静态文件,然后通过 SSH 将public目录的内容同步到你的 VPS 上。 整个过程配置一次,之后你只要git push,网站都会自动更新。 下面是一个经过实践检验的自动化部署方案,包含配置步骤和完整的 YAML 代码。 1. 配置 GitHub Actions 第一步:准备工作——在 GitHub 仓库中配置密钥 为了让 GitHub Actions 能安全地登录你的 VPS,你需要将 VPS 的登录凭证存储在 GitHub 仓库的“Secrets”中。 在你的 GitHub 仓库页面,点击 Settings → Secrets and variables → Actions。 点击 New repository secret,添加以下两个密钥: SERVER_IP:你的VPS公网IP地址(或者可解析的网址亦可)。 SSH_PRIVATE_KEY:你的VPS登录私钥。 如果你没有密钥对,可以在本地通过ssh-keygen -t rsa -b 4096 -f ${private_key_path}生成: ...

March 2, 2026 · 2 min · Carl Cui

基于 hugo 构建个人博客

基于 hugo 构建个人技术博客剥离了数据库和动态脚本的复杂性,让你能完全专注于写作和技术分享。另外,hugo 的工作方式可以非常自然地借助 git 对文章进行版本管理,特别适合有一定命令行基础的人。 1. 准备工作,安装必要工具 需要安装两个基础软件: Git:用于文档版本管理和后续的主题安装。 Hugo (扩展版):核心的静态网站生成器。建议安装带有“extended”后缀的版本,以确保支持Sass/SCSS等现代主题特性。 macOS用户:brew install hugo 国内用户可能需要为 brew 配置 proxy,例如为 brew 配置 SOCKS5 代理: export all_proxy=socks5://$HOST:$PORT 或者为 brew 配置 HTTP 代理: export http_proxy=http://$HOST:$PORT Windows用户:可以使用 scoop install hugo-extended,或从Hugo GitHub Releases页面下载。 安装完成后,在终端输入 hugo version 验证是否成功。 注意:不同 hugo 主题对 hugo 的版本有一定需求,可以从 Hugo GitHub Releases 页面下载特定版本 2. 搭建博客骨架 在终端执行以下命令,Hugo会为你生成一个包含所有必要目录的站点骨架。 # 创建一个名为 "my-blog" 的站点(可替换为你喜欢的名字) hugo new site my-blog Congratulations! Your new Hugo site was created in ./my-blog. Just a few more steps... 1. Change the current directory to ./my-blog. 2. Create or install a theme: - Create a new theme with the command "hugo new theme <THEMENAME>" - Or, install a theme from https://themes.gohugo.io/ 3. Edit hugo.toml, setting the "theme" property to the theme name. 4. Create new content with the command "hugo new content <SECTIONNAME>/<FILENAME>.<FORMAT>". 5. Start the embedded web server with the command "hugo server --buildDrafts". See documentation at https://gohugo.io/. # 进入站点目录 cd my-blog # 目录下生成了 `archetypes`、`content`、`themes`等文件夹和 `hugo.toml` 配置文件 tree . ├── archetypes │ └── default.md ├── assets ├── content ├── data ├── hugo.toml ├── i18n ├── layouts ├── static └── themes 8 directories, 2 files # 初始化Git仓库,方便后续管理主题和代码 git init # 为项目配置 .gitignore 文件 .gitignore 文件示例: # 构建输出目录 /public/ # 本地构建缓存与锁文件 /resources/ /.hugo_build.lock # 编辑器/IDE辅助文件 /assets/jsconfig.json /hugo_stats.json # 操作系统无关文件 .DS_Store Thumbs.db 3. 选择并配置主题 Hugo本身不带默认样式,你需要选择一个主题。 ...

March 2, 2026 · 2 min · Carl Cui