以我的 github hugo 博客为例,讲解如何搭建 hugo 博客
1. 下载 hugo 客户端,添加 PATH
-
新建一个文件夹,用 cmder 打开,运行
hugo new site zen-yang.github.io-creator -
用 VSCode 打开 zen-yang.github.io-creator 文件夹,新开一个终端,运行
git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
echo 'theme = "ananke"' >> config.toml
hugo new posts/你的博客名字.md
-
打开 content/posts 文件夹下的 你的博客名字.md 文件
-
写博客内容,最后修改 draft 为 false(draft 为草稿的意思)
-
终端 运行
hugo server -D -
修改 config.toml 将 languageCode 改为 zh-Hans 将 title 改为你自己博客的 title
-
再新开一个终端,运行命令 hugo,然后 cd public
-
新建 .gitignore 文件 写上 /public/
-
终端中,进入了 public 文件夹后,
git init
git add .
git commit -v
// commit 详情中写 第一次部署,关闭详情文件
- 自己的 github 创建 zen-yang.github.io 项目
git remote add origin git@github.com:zen-yang/zen-yang.github.io.git
git push -u origin master
在 VSCode 终端运行这两行代码
- 去到 zen-yang.github.io 项目,Settings 往下拉,看到 GitHub Pages,选择 source为 master,点击 zen-yang.github.io/