Skip to content
Donghai's Blog
Go back

Hugo常用命令速查表

Hugo 是一个基于 Go 语言的静态网站生成器,以其极快的构建速度著称。本文记录的是自己在 Hugo 开发中最常用的命令,方便日常查阅。

封面图

Table of contents

Open Table of contents

项目初始化和配置

# 在当前目录创建新站点
hugo new site my-site

# 指定主题(以 PaperMod 为例)
cd my-site
git init
git submodule add https://github.com/adityatelange/hugo-PaperMod.git themes/PaperMod

内容管理

创建内容

# 创建普通文章
hugo new posts/my-first-post.md

# 创建带有分类的文章
hugo new posts/tech/hugo-tutorial.md

本地开发与预览

# 基础启动
hugo server

# 包含草稿(draft: true 的文章)
hugo server -D

# 指定端口(默认 1313)
hugo server -p 8080

# 禁用 LiveReload
hugo server --disableLiveReload

# 绑定所有网络接口(局域网可访问)
hugo server --bind=0.0.0.0 --baseURL=http://your-ip:1313

高级选项

# 内存缓存,加快构建速度
hugo server --renderToMemory

# 指定配置文件
hugo server --config config.toml

# 多环境配置(支持 config/production 等)
hugo server --environment development

构建与部署

生成静态文件

# 基础构建
hugo

# 指定输出目录(默认 ./public)
hugo -d docs

# 构建时包含未来的文章
hugo --buildFuture

# 构建时包含过期文章
hugo --buildExpired

# 生产环境构建(移除草稿、未来和过期文章)
hugo --minify --environment production

构建优化选项

# 压缩 CSS/JS
hugo --minify

# 启用模板指标分析
hugo --templateMetrics

# 启用 GC(垃圾回收)优化内存
hugo --gc

# 强制所有文件重新构建(忽略缓存)
hugo --ignoreCache

主题管理

主题操作

# 初始化主题子模块
git submodule add https://github.com/theme-author/theme-name.git themes/theme-name

# 更新主题
git submodule update --remote --merge

# 列出所有可用主题
hugo theme list

# 安装主题(通过 Hugo Modules)
hugo mod get github.com/theme-author/theme-name

实用工具命令

版本信息

# 查看 Hugo 版本
hugo version

# 查看详细环境信息
hugo env

配置检查

# 检查配置文件语法
hugo config

# 列出所有配置项
hugo config mounts

# 检查当前配置的详细输出
hugo config --format json

内容统计与分析

# 列出所有内容
hugo list all

# 列出草稿
hugo list drafts

# 列出未来发布的内容
hugo list future

# 列出已过期的内容
hugo list expired

Share this post on:

Previous Post
PaperMod添加不蒜子记录浏览量
Next Post
什么是VV/RV/PV/UV?
BlogsClub Meo Forever Blog