安装hugo
- 官网地址: https://gohugo.io/
- github官网地址:https://github.com/gohugoio/hugo,进入后再进入release页,然后下载 linux的安装文件,安装之。
初步使用
- 生成hugo 博客目路并自动初始化
1 2 3
| $ mkdir myblog $ cd myblog $ hugo new site myhugo
|
archetypes 目录中定义了Hugo创建markdown文件的模板。
content 存放markdown文件。
data 存放数据文件。
layouts 存放模板文件。
static 存放静态文件。
themes 存放主题。
config.toml 配置文件。
- 下载主题,并使用之
1 2 3 4 5 6
| $ cd ~/myblog/myhugo $ git clone https://github.com/dillonzq/LoveIt.git themes/LoveIt $ git clone https://github.com/panr/hugo-theme-terminal.git themes/terminal $ git clone https://github.com/wowchemy/starter-hugo-research-group themes/research-group
$ hugo server -t LoveIt
|
- 采用下载的主题范例
以 hugo-serif-theme主题为例
1 2 3 4 5 6
| $ cd myblog/themes/hugo-serif-theme/ $ cp -r exampleSite ../../ $ cd ~/myblog/ $ mv exampleSite serif $ hugo server --source=serif
|
- 修改 ~/myblog/myhugo/config.toml文件,增加
theme = “XXXX”,可指定默认主题
编写第一个文章
- 生成文档
1
| $ hugo new posts/first_post.md
|
- 内容
1 2 3 4 5 6 7 8 9 10
| --- title: "Hugo学习笔记一,初步运行一遍" date: 2022-11-18T11:40:38+08:00 tags: ["Hugo"] categories: ["stucy"] toc: enable: true description: 学习hugo的笔记1,初接触 draft: true ---
|
- 一些经验
其实 hugo 在新建文章时,不一定要 hugo new posts/xxxx.md。
可以 hugo new xxxx.md,这样会在 content 目录下新建文件 xxxx.md,网站中可以通过 /xxxx 来访问。
还可以 hugo new /xxxx.md,这样会在 content 目录下的 目录下新建文件 xxxx.md(若文件夹 不存在则会自动新建),网站中可以通过 //xxxx 来访问。此时,在网站中访问 / 即可显示目录下所有文章的列表,实现文章聚合。
对于每一个 的聚合,我们可以在网站目录下的 archetypes 目录中,新建一个 .md 文件,则可创建该类聚合的模板,后续的每一次 hugo new /xxxx.md 都会以 .md 为模板。
在本地启动网站
1
| $ hugo server -D --bind "0.0.0.0"
|
部署到GitHub
- 在github上建立自己的仓库,比如 laoshiren,那么未来你的主页就会是laoshiren.github.io
- 修改 ~/myblog/myhugo/config.toml文件
修改config.toml文件中的baseURL为https://laoshiren.github.io
- 执行
1 2 3 4 5 6 7
| cd public git init git remote add origin https://github.com/GitHub账号名/laoshiren.github.io.git
git add . git commit -m "updated %date%,%time%" git push origin master
|