这是一个无外部主题依赖的 Hugo 中文博客。源码保存在 main 分支;每次推送后,GitHub Actions 会构建 public/ 并直接部署到 GitHub Pages。
线上地址:https://ymj4023.github.io/
先安装 Hugo Extended,建议使用 0.164.0 或兼容的新版本。
cd D:\ymj\gitwork\ymj4023.github.io
hugo server打开终端显示的本地网址即可预览。需要同时显示草稿时运行 hugo server -D。
新文章放在 content/posts:
hugo new content posts/my-new-post.md编辑生成的 Markdown 文件,把 front matter 中的 draft 改为 false(或删除该字段),然后提交并推送:
git add .
git commit -m "content: publish a new post"
git push-
在 GitHub 创建一个名为
ymj4023.github.io的仓库。用户主页仓库名必须与账号名完全一致。 -
不要在 GitHub 端额外生成 README、
.gitignore或许可证,避免首次推送发生历史冲突。 -
在本地仓库中连接远程并推送:
git remote add origin https://github.com/ymj4023/ymj4023.github.io.git git push -u origin main
-
打开仓库的 Settings → Pages。
-
在 Build and deployment 下,把 Source 设为 GitHub Actions。
-
打开 Actions 页面,等待
Build and deploy Hugo site工作流变绿。
.github/workflows/hugo.yaml 自动构建与部署
content/posts/ Markdown 文章
layouts/ Hugo 页面模板
static/css/site.css 响应式样式
hugo.yaml 站点配置
tests/verify.ps1 本地验收测试
运行完整验收测试:
.\tests\verify.ps1 -HugoPath "C:\path\to\hugo.exe"构建产物不提交到仓库;GitHub Actions 会在部署时重新生成 public/。