使用Hugo和GitHub Pages创建静态网站个人博客

不需要服务器,不需要域名,不需要数据库,可以选择模版,内容为Markdown格式。

Hugo:https://gohugo.io

文档:https://gohugo.io/getting-started/quick-start/

中文文档:https://www.gohugo.org/

下载:https://github.com/gohugoio/hugo/releases/download/v0.139.2/hugo_0.139.2_windows-amd64.zip

皮肤列表:https://www.gohugo.org/theme/

bash 复制代码
hugo new site hugo-site

cd hugo-site

git init

git submodule add https://github.com/spf13/hyde.git themes/hyde

echo "theme = 'hyde'" >> hugo.toml

hugo new about.md
hugo new post/first.md

生成内容中draft=true,即为草稿的意思,通常情况下,Hugo并不会发布和编译草稿文章。因此需要将其改为false,现在就改。

如果你想对主题做一些自定义修改,你可以Fork对应的主题到自己的仓库,然后修改。

bash 复制代码
hugo server --buildDrafts
或者
hugo server -D

访问 http://localhost:1313

假设你需要部署在 GitHub Pages 上,首先在GitHub上创建一个Repository,命名为:raoxiaoya.github.io (raoxiaoya替换为你的github用户名)。

修改hugo.toml文件中的baseURL的值为'https://raoxiaoya.github.io'

hogo.toml

bash 复制代码
baseURL = 'https://raoxiaoya.github.io'
languageCode = 'en-us'
title = 'My New Hugo Site'
theme = 'hyde'

编译

bash 复制代码
hugo

其默认指令就是build

你的静态网站就在public命令下。

public设置为submodule,修改.gitmodules

bash 复制代码
[submodule "themes/hyde"]
	path = themes/hyde
	url = https://github.com/spf13/hyde.git
[submodule "public"]
	path = public
	url = https://github.com/raoxiaoya/raoxiaoya.github.io.git

提交public

bash 复制代码
cd public
git init
git remote add origin https://github.com/raoxiaoya/raoxiaoya.github.io.git
git pull origin master
git add . && git commit -m "public first commit" && git push -u origin master

访问 https://raoxiaoya.github.io/

创建hugo-site仓库,并提交提仓库

bash 复制代码
cd ../
git remote add origin https://github.com/raoxiaoya/hugo-site.git
git pull origin master
git add . && git commit -m "hugo-site first commit" && git push -u origin master

如果你想在博客中加入评论功能,可以使用 utteranc,不需要账号系统,直接基于github平台。

相关推荐
CoderJia程序员甲18 分钟前
GitHub 热榜项目 - 日榜(2026-03-25)
人工智能·ai·大模型·github·ai教程
MicrosoftReactor2 小时前
技术速递|底层机制:GitHub Agentic Workflows 的安全架构
安全·ai·github·agent·安全架构
CoovallyAIHub2 小时前
AAAI 2026 | AnoStyler:文本驱动风格迁移实现零样本异常图像生成,轻量高效(附代码)
算法·架构·github
CoovallyAIHub2 小时前
500M参数就能跑视觉语言模型?Moondream把VLM塞进了边缘设备
算法·架构·github
徐小夕3 小时前
一个普通Word文档,为什么99%的开源编辑器都"认怂"了?我们选择正面硬刚
vue.js·后端·github
Mahut4 小时前
从零构建神经影像可视化库:neuroviz 的架构设计与实现
前端·javascript·github
m0_694845575 小时前
Docker 从入门到实践教程:docker_practice 完整学习指南
运维·服务器·docker·容器·云计算·github
TT哇6 小时前
将 Gitee 混合项目仓库拆分并精准迁移至 GitHub(保留完整 Commit 历史)
gitee·github
阿里嘎多学长7 小时前
2026-03-24 GitHub 热点项目精选
开发语言·程序员·github·代码托管