本文简单记录使用 Hugo 静态站点生成器搭建个人博客,并通过 GitHub Actions 自动部署到 GitHub Pages 的过程。
环境准备
- 安装 Hugo(本站使用 v0.157.0)
- 安装 Git
- 一个 GitHub 账号
创建 Hugo 站点
hugo new site my-blog
cd my-blog
git init
安装主题
这里使用 Beautiful Hugo 主题,通过 Git Submodule 方式引入:
git submodule add https://github.com/halogenica/beautifulhugo.git themes/beautifulhugo
主题自带了一个 exampleSite 目录,可以将其内容复制到项目根目录作为起步模板:
cp -r themes/beautifulhugo/exampleSite/* .
然后在 hugo.toml 中确认主题配置:
其他需要自定义的配置项包括 title、subtitle、[Params.author] 中的个人信息、[[menu.main]] 导航菜单等,按需修改即可。
本地预览:
浏览器访问 http://localhost:1313/ 即可看到效果。
编写文章
在 content/post/ 目录下创建 Markdown 文件:
hugo new content/post/my-first-post.md
文件开头的 front matter 控制标题、日期、标签等元信息:
[阅读全文]