介绍
hugo + gitee搭建个人博客,使用gitee代替github是因为国内访问速度问题。
hugo直接在仓库可以安装sudo apt install hugo
,这个链接是它的官方网页。
hugo new xxx.md
在post中新建Markdown格式的文章,注意此时在开头属性里有draft: true的标志,这会导致此篇文章不能发布。
后期需要删除此行。
hugo -t $theme
生成public文件夹中的静态网页。
hugo server
可以本地起一个服务器,这时通过浏览器查看网页效果。
git submodule
hugo主题和静态网页是另外的git库,为了方便管理,引入git submodule的用法。
比如我使用的hugo主题是even,可以使用命令
1
|
git submodule add https://gitee.com/xxxxx/hugo-theme-even.git themes/even
|
来添加子模块。
gitee提供的静态网页,在仓库的服务->Gitee Pages可以找到。即新建一个同名的仓库就可以了。同样添加
1
|
git submodule add -b master https://gitee.com/lclei/lclei.git public
|
添加后,主目录里会有.gitmodules文件记录。
1
2
3
4
5
6
7
8
|
$ cat .gitmodules
[submodule "themes/even"]
path = themes/even
url = https://gitee.com/gkzhb/hugo-theme-even.git
[submodule "public"]
path = public
url = https://gitee.com/lclei/lclei.git
branch = master
|
git没有提供submodule的删除命令。有出错等情况,可以去.git目录下找到modules目录,删除对应submodule。
部署
最后记录自己的deploy.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
|
#!/bin/sh
# If a command fails then the deploy stops
set -e
printf "\033[0;32mDeploying updates to Gitee...\033[0m\n"
# Build the project.
hugo -t even # if using a theme, replace with `hugo -t <YOURTHEME>`
# Go To Public folder
cd public
# Add changes to git.
git add .
# Commit changes.
msg="rebuilding site $(date)"
if [ -n "$*" ]; then
msg="$*"
fi
git commit -m "$msg"
# Push source and build repos.
git push origin master
cd ..
|