Summary
使用hugo构建blog,并使用github进行发布。
Mac OS
Window
1
|
$ choco install hugo -confirm
|
Linux
可从该网站选择合适的主题并下载到本地,一般是通过git clone,本文以even
主题为例构建自己的blog。
通常情况下每个Theme都有一个exampleSite目录为Theme示例,执行一下命令来初始化Blog项目目录
1
2
3
4
|
$ mv hugo-theme-even/exampleSite .
$ mkdir -p exampleSite/themes/even
$ mv hugo-theme-even exampleSite/themes/even.
$ mv exampleSite hugo-blog-even
|
Blog项目目录如下:
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
|
$ tree -L 3 -I "public"
.
├── config.toml # 配置文件
├── content # markdown文件目录
│ ├── about.md
│ └── post
│ ├── default
│ └── hugo
├── resources
│ └── _gen
│ ├── assets
│ └── images
└── themes # 主题
└── even
├── CHANGELOG.md
├── LICENSE.md
├── README-zh.md
├── README.md
├── archetypes
├── assets
├── i18n
├── images
├── layouts
├── resources
├── static
└── theme.toml
|
也可使用Hugo命令生成站点,然后再引入主题
1
2
3
4
|
$ hugo new site path/to/site
$ cd path/to/site
$ mkdir theme && cd theme
$ git clone git theme
|
启动Hugo服务
服务默认启动在1313
端口,如果正常访问则表示项目已经搭建好。
部署到Github
在Github中创建一个Repository,命名为<username>.github.io
修改config.toml
文件中的baseURL
字段
1
|
baseURL="http://<username>.github.io/"
|
编译Hugo项目
构建成功后会生成public目录,然后将该目录提交到远端.github.io仓库中
1
2
3
4
5
6
|
$ cd public
$ git init
$ git remote add origin you repository url
$ git add .
$ git commit -m "hugo blog"
$ git push -u origin master
|
之后可通过<username>.github.io
访问该blog。