golang,go,博客,开源,编程
Hugo
是一个基于 Go 语言 开发的 静态网站生成器(Static Site Generator,SSG),以其 极快的构建速度、强大的功能和灵活的模板系统 而闻名。它主要用于生成 博客、文档网站、企业站点和个人项目 等。
Blackfriday
解析 Markdown,支持 扩展语法(如表格、脚注、代码高亮等)。content
目录来管理文章、页面等。brew install hugo
go install
go install github.com/gohugoio/hugo@latest
PATH
。hugo new site my-site
cd my-site
Hugo 会生成一个基本的站点结构:
my-site/
├── archetypes/ # 文章模板
├── content/ # 文章内容
├── layouts/ # 自定义页面布局
├── static/ # 存放静态资源 (CSS, JS, Images)
├── themes/ # 主题目录
├── config.toml # 站点配置文件
Hugo 支持主题,可以从 Hugo Themes 选择一个:
git submodule add https://github.com/theNewDynamic/gohugo-theme-ananke.git themes/ananke
echo 'theme = "ananke"' >> config.toml
hugo new posts/my-first-post.md
然后编辑 content/posts/my-first-post.md
:
---
title: "我的第一篇文章"
date: 2025-03-14T10:00:00+08:00
draft: false
---
这里是我的第一篇 Hugo 文章!
hugo server
然后访问 http://localhost:1313
查看网站。
hugo -D
这将在 public/
目录中生成 HTML 文件,准备部署。
my-site/
├── archetypes/ # 默认文章模板
├── content/ # 存放 Markdown 文章
│ ├── posts/ # 博客文章
│ ├── about.md # 单页面,如“关于我们”
├── layouts/ # 站点模板
│ ├── _default/ # 通用布局
│ ├── index.html # 首页模板
├── static/ # 存放静态资源 (CSS, JS, Images)
├── themes/ # 存放 Hugo 主题
├── config.toml # 配置文件
└── public/ # 生成的静态网站文件
Hugo 提供短代码,可在 Markdown 中嵌入动态内容:
{{< youtube w7Ft2ymGmfc >}} # 嵌入 YouTube 视频
在 config.toml
中启用:
defaultContentLanguage = "en"
[languages]
[languages.en]
title = "My Blog"
[languages.zh]
title = "我的博客"
然后将内容放入 content/en/
和 content/zh/
目录中。
hugo
cd public
git init
git add .
git commit -m "Deploy Hugo site"
git push -f git@github.com:yourusername/yourrepo.git master:gh-pages
hugo
public/
。功能 | Hugo | Jekyll | Gatsby |
---|---|---|---|
语言 | Go | Ruby | JavaScript |
速度 | 🚀 超快 | 慢 | 中等 |
模板语言 | Go Templates | Liquid | React |
依赖 | 无 | 需要 Ruby | 需要 Node.js |
多语言支持 | ✅ 是 | ❌ 否 | ✅ 是 |
适合场景 | 文档/博客 | 个人博客 | 动态网站 |
Docusaurus
)。Hugo 是目前最流行的静态网站生成器之一,具有 超快的构建速度、强大的模板系统、多语言支持,并且 无依赖,适用于博客、文档网站和企业网站。