Hugo入门
Hugo 是一个静态网页生成程序,基于Golang实现,但其打包后的程序不依赖外部环境,这点要比Hexo和Jekyll要好一些,另外因为是Golang实现的,其运行速度非常快,笔者选择Hugo做为静博客的生成程序
安装
https://gohugo.io/getting-started/installing/
# 笔者使用Manjaro系统(Linux)做为开发桌面系统,
# 可以直接通pacman命令来安装,其它系统的安装方法参考官方文档
$ sudo pacman -S hugo
# 查看版本以确认是否成功安装
$ hugo version
Hugo Static Site Generator v0.64.0/extended linux/amd64 ...
示例
https://gohugo.io/getting-started/quick-start/
https://gohugo.io/getting-started/usage/
# 通过 help 子命令可以查看 hugo 的所有命令和子命令用法,
# 当然你也可以通过 man 来查看
# 创建站点,需要指定一个目录,需要注意这个目录可以不存在,
# 但如果存在,则必须是一个空目录
$ hugo new site hugo.zlikun.com
# 目录结构
$ tree hugo.zlikun.com/
hugo.zlikun.com/
├── archetypes
│ └── default.md
├── config.toml
├── content
├── data
├── layouts
├── static
└── themes
6 directories, 2 files
# 最主要的几个目录/文件分别是:
# config.toml 或者 config.yaml,我个人习惯于使用后者
# themes 主题目录,至少需要一个主题
# content 文章目录,编写的文章都存放于该目录中
# 其它目录按需要使用,具体参考官方文档:
# https://gohugo.io/getting-started/directory-structure/
# 版本控制,作为程序员这一步算是必备的了,后面安装主题时会使用子模块的方式来安装,
# 主题一般托管在Github等Git托管平台上
$ cd hugo.zlikun.com/
$ git init
# 安装主题
# https://themes.gohugo.io/
# 注意有些主题可能需要使用其自身提供的配置文件模板(包含一些特定配置),
# 这里使用 gohugo-theme-ananke 主题,因为访问 Github 不是很流畅,
# 所以我把主题导入到 Gitee 上了,这样也方便后期定制修改
$ git submodule add https://gitee.com/zlikun/gohugo-theme-ananke.git themes/gohugo-theme-ananke
# 创建文章,文件位于content子目录下,使用Markdown语法编写文章,
# 使用 post 子目录是为了自动生成集合页(文章清单页)
$ hugo new post/hello.md
# 测试服务,因为没有修改配置文件,所以通过命令行来指定主题,
# 另外通过 --buildDrafts 参数(等价于 -D)指定构建时包含草稿
$ hugo serve --theme=gohugo-theme-ananke --buildDrafts
# 此时在浏览器中访问:http://localhost:1313/ 即可看到生成的网页
GitHub Pages
# 生成网页,实际在Github Pages服务上部署的是生成好的HTML网页文件
$ hugo --theme=gohugo-theme-ananke -D
# 部署 Github Pages 服务,其实就是按Github要求将静态文件上传到指定仓库
$ cd public
$ git init
$ git remote add origin https://github.com/zlikun/zlikun.github.io.git
$ git add .
$ git commit -m 2020/02/26
$ git push -uf origin master
# 部署后即可通过个人域名来访问:https://zlikun.github.io,
# 当然也可以通过CNAME机制来使用独立域名访问,如:https://www.zlikun.com