本文作为hugo静态网站搭建记录的进阶版,主要是考虑到了多平台的问题。由于我们没有自己的服务器,网站托管在Github上,如何在其他平台上更新自己的网站就成为了一个问题。因此按照官网的指导,写了本篇文章,把网站的源代码文件和可执行文件都存储到GitHub的仓库中。当我们更换了一个平台时,只需把源代码文件从GitHub上pull下来(二进制文件作为该仓库的子模块),即可写文章并推送到博客上。

如果你还没有了解过hugo,建议先看我之前的文章。

首先,在github中建立两个名为blogxxx.github.io的仓库,前者用来存储源代码文件,后者用来存储可执行文件。

网站的生成命令如下:

hugo new site blog
cd blog
git init
git remote add origin git@github.com:wangzihe1996/blog.git
git pull origin master
git clone https://github.com/spf13/hyde.git themes/hyde
hugo new about.md
hugo new post/test.md

about.mdtest.md中添加一些内容用来测试,同时设置draft为false。

修改config.toml配置文件,修改第一行baseURL为baseURL = "http://xxx.github.io/",并添加一行theme = "hyde",更多配置可以参考Hyde主题的首页

然后使用hugo server命令,来生成网站,打开localhost:1313来查看有没有问题,测试没有问题后,用ctrl+c来终止测试。

然后把网站的源代码文件和可执行文件推送到GitHub的仓库中。

cd /c/hugo/blog
git submodule add -b master git@github.com:wangzihe1996/wangzihe1996.github.io.git public
hugo
cd public
git add -A
git commit -m "init&example"
git push -u origin master
cd ..
git add -A
git commit -m "init&example"
git push --recurse-submodules=check -u origin master

以后的日常推送为:

cd /c/hugo/blog
hugo
cd public
git add -A
git commit -m "update"
git push -u origin master
cd ..
git add -A
git commit -m "update"
git push --recurse-submodules=check -u origin master