使用HUGO搭建个人网站。
把本地托管到GitHub
本地terminal中cd到HUGO项目目录
将本地repo初始化为一个新的repo 在本地创建一个
.gitignore
文件,内容如下:# Compiled Object files, Static and Dynamic libs (Shared Objects) *.o *.a *.so # Folders _obj _test # Architecture specific extensions/prefixes *.[568vq] [568vq].out *.cgo1.go *.cgo2.c _cgo_defun.c _cgo_gotypes.go _cgo_export.* _testmain.go *.exe *.test /public .DS_Store .hugo_build.lock # resources/_gen/
然后执行:
echo "# SukiXuu.github.io" >> README.md # 创建README.md文件 git init # 初始化本地仓库,在hugo安装submodule时已经初始化过了,这里不用再初始化
暂存所有文件,commit到本地仓库
git add. # Adds the files in the local repository and stages them for commit. 若要取消暂存文件,请使用 # `git reset --hard HEAD^` 撤销最后一次提交, 不保留任何提交 # `git reset --soft HEAD^` 撤销最后一次提交,保留提交记录到暂存区
git commit -m "First Commit"
关联远程仓库:
git branch -M main git remote add origin https://github.com/SukiXuu/SukiXuu.github.io # `git remote remove origin` 移除已有的远程仓库origin
把本地仓库推送到远程仓库:
git push -u origin main
- 更改GitHub Actions的配置文件,使其能够自动部署网站。
- 启用 GitHub Actions 并配置 Pages: 进入你的仓库页面,点击 Settings; 找到左侧的 Pages 选项,选择 GitHub Actions 作为 Source。
- settings -> actions -> new workflow -> set up a workflow yourself -> 选择HUGO模板 -> 编辑yaml文件 -> 找到push到main分支的步骤 -> 找到deploy步骤 -> 编辑deploy步骤,对比PaperMod Demo 的 部署文件,自行做相应修改。
- 保存并运行workflow。
- 等待几分钟,网站应该已经部署成功。在之后的github提交会自动部署到网站。
N.B. 子模块git submodule的使用
查看子模块状态:
cat .gitmodules
git submodule
查看子模块内容:
git submodule update --init --recursive
cd path/to/submodule # 进入子模块文件夹
git status # 查看子模块的状态
添加/更新子模块:
git submodule add <repo_url> path/to/submodule # 添加子模块
git submodule update --remote # 更新子模块到最新提交
删除子模块:
git rm --cached path/to/submodule # 删除子模块缓存
rm -rf .git/modules/path/to/submodule # 删除子模块文件夹