This article refers to the traditional installation method of cloning the theme locally as Git submodule. It describes how to install, upgrade the theme, and write new articles. While this installation method is still widely used, we recommend to install the theme as Hugo module.

安装#

从头开始创建站点#

1$ hugo new site myblog
2$ cd myblog
3$ git init
4$ git submodule add https://github.com/razonyang/hugo-theme-bootstrap themes/hugo-theme-bootstrap
5$ cp -a themes/hugo-theme-bootstrap/exampleSite/* .
6$ hugo mod npm pack
7$ npm install
8$ hugo server

如果你使用的是 Windows,请改用 xcopy .\themes\hugo-theme-bootstrap\exampleSite /E

安装到已有站点#

 1$ cd myblog
 2$ git submodule add https://github.com/razonyang/hugo-theme-bootstrap themes/hugo-theme-bootstrap
 3$ mkdir config
 4$ cp -a themes/hugo-theme-bootstrap/exampleSite/config/* ./config
 5$ cp -r themes/hugo-theme-bootstrap/exampleSite/content/about/ \
 6  themes/hugo-theme-bootstrap/exampleSite/content/archives/ \
 7  themes/hugo-theme-bootstrap/exampleSite/content/categories/ \
 8  themes/hugo-theme-bootstrap/exampleSite/content/contact/ \
 9  themes/hugo-theme-bootstrap/exampleSite/content/offline/ \
10  themes/hugo-theme-bootstrap/exampleSite/content/search/ \
11  themes/hugo-theme-bootstrap/exampleSite/content/series/ \
12  themes/hugo-theme-bootstrap/exampleSite/content/tags/ \
13  ./content
14$ hugo mod npm pack
15$ npm install
16$ hugo server

如果你重新克隆仓库,你将需要通过 git submodule update --init --recursive 更新 submodule,或者 git clone --recursive <repo>

升级#

1$ cd themes/hugo-theme-bootstrap
2$ git fetch
3$ git checkout [version]
4$ cd ../../
5$ hugo mod npm pack
6$ git add themes/hugo-theme-bootstrap package.json
7$ git commit -m 'Upgrade the theme'
  • [version] 替换为最新的版本。所有版本可以通过命令 git tag -l | sort -rV 列出。
  • 你也可以直接使用 master 分支以获取最新的修改。