纸上得来终觉浅,绝知此事要躬行。
- 陆游 《冬夜读书示子聿》

hugo使用教程

2025-08-30 01:27 · 6 minutes read

简单介绍

Hugo是一个静态web网站生成器。同类软件有:hexo,Jekyll。相比后两个,我更喜欢Hugo,它由go语言编写,速度快,直接一个二进制程序,没有任何依赖,就很简洁。

使用方法

创建一个website 项目

1hugo new site <projectName>

进入项目目录

1cd <projectName>

添加主题, 主题网站: https://themes.gohugo.io

1git init
2git submodule add <主题git地址> themes/<主题名称>

打开hugo.toml文件,添加下面内容设置主题

1theme = '<主题名称>'

创建文章

1hugo new posts/<文章名称>.md

在 content/posts/ 目录下可以找到刚刚创建的<文章名称>.md文件,内容类似这样:

1+++
2date = '2025-08-30T02:02:00+08:00'
3draft = true
4title = 'Test'
5+++

上面的被 “+++” 括起来的叫 ”Front Matter“,就是记录了文章的一些信息。

常见Front Matter 参数

运行本地web server,查看网站效果

1hugo server

运行结果部分内容如下

1Built in 1 ms
2Environment: "development"
3Serving pages from disk
4Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
5Web Server is available at http://localhost:1313/ (bind address 127.0.0.1) 
6Press Ctrl+C to stop

找到 http://localhost:1313/ 到浏览器访问即可

构建静态站点

1hugo

生成的静态站点文件在public目录中,找个静态网站托管平台托管即可。

清理缓存

1hugo --gc

或者

1rm -rf public

总结

简单记录下hugo的使用方法。


🌙