Hugo 简介

Hugo 是一个用 Go 语言编写的静态网站生成器,以其出色的性能和易用性而闻名。

安装 Hugo

Windows

使用 winget 安装(推荐):

winget install Hugo.Hugo.Extended

macOS

使用 Homebrew 安装:

brew install hugo

Linux

使用包管理器安装:

# Ubuntu/Debian
sudo apt install hugo

# Arch Linux
sudo pacman -S hugo

创建新站点

# 创建新站点
hugo new site myblog

# 进入站点目录
cd myblog

# 初始化 Git 仓库
git init

安装主题

这里以 PaperMod 主题为例:

git submodule add --depth=1 https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod

配置站点

编辑 hugo.toml 文件:

baseURL = 'https://yourusername.github.io/'
languageCode = 'zh-cn'
title = '我的博客'
theme = 'PaperMod'

创建文章

hugo new posts/my-first-post.md

本地预览

hugo server -D

访问 http://localhost:1313 查看你的网站。

构建站点

hugo

生成的静态文件会保存在 public/ 目录。

部署到 GitHub Pages

使用 GitHub Actions 自动部署,详见下一篇文章。


Happy blogging! 📝