初始化一个 Hugo 网站:

1. 打开终端/CMD,执行初始化命令:

hugo new site my-website

这会创建名为 my-website 的网站目录

2. 进入网站目录:

cd my-website

3. (建议)添加主题,以最常用的 Ananke 主题为例:

git init  # 初始化Git仓库
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke

4. 修改配置文件 hugo.toml,末尾添加:

theme = "ananke"

5. 创建第一篇内容:

hugo new posts/my-first-post.md

6. 启动本地预览:

hugo server -D

打开浏览器访问 http://localhost:1313 就能看到网站啦!

补充说明:

  • 新建站点后会看到这些默认目录结构:
  ├── archetypes/    # 内容模板
  ├── content/       # 网站内容
  ├── layouts/       # 自定义模板
  ├── static/        # 静态文件
  ├── themes/        # 存放主题
  └── hugo.toml      # 配置文件
  • 如果要生成静态文件,执行:
hugo -D

生成的文件会在 public/ 目录中

刚开始建议先通过主题熟悉 Hugo 的工作流程,后续可以按需调整主题或开发自定义模板。