使用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平台。

相关推荐
Natsume17102 小时前
嵌入式开发:GPIO、UART、SPI、I2C 驱动开发详解与实战案例
c语言·驱动开发·stm32·嵌入式硬件·mcu·架构·github
荔枝吻2 小时前
【AI总结】Git vs GitHub vs GitLab:深度解析三者联系与核心区别
人工智能·git·github
幻凡ss3 小时前
github pages使用免费CDN加速-netlify
github·github pages·github cdn·github pages加速·netlify加速github·hexo博客免费cdn加速·个人博客免费cdn加速
我是哪吒5 小时前
分布式微服务系统架构第155集:JavaPlus技术文档平台日更-Java线程池实现原理
后端·面试·github
DeepSeek-大模型系统教程14 小时前
推荐 7 个本周 yyds 的 GitHub 项目。
人工智能·ai·语言模型·大模型·github·ai大模型·大模型学习
ai小鬼头16 小时前
AIStarter最新版怎么卸载AI项目?一键删除操作指南(附路径设置技巧)
前端·后端·github
扣脚大汉在网络20 小时前
github如何创建一个自己的仓库保姆级教程
github
不午睡的探索者1 天前
告别性能瓶颈!Python 量化工程师,进击 C++ 高性能量化交易的“必修课”!
c++·github
光溯星河1 天前
【实践手记】Git重写已提交代码历史信息
后端·github
独立开阀者_FwtCoder1 天前
URL地址末尾加不加 "/" 有什么区别
前端·javascript·github