安装

MacOS

  1. brew install hugo
  1. hugo new site foo/

目录结构

  1. archetypes/
  2. content/
  3. layouts/
  4. static/
  5. config.toml

创建文章

  1. hugo new posts/about.md
  2. hugo new posts/article.md

主题

  1. cd themes
  2. git clone https://github.com/spf13/hyde.git

本地运行测试

  1. hugo server -D --theme=hyde --buildDrafts

运行后访问localhost:1313

部署

去掉文章头部的draft=true,执行以下命令会生成public目录。

  1. hugo -D --theme=hyde --baseUrl="https://luning.wang"

推到Git上

  1. cd public
  2. git init
  3. git remote add origin https://github.com/coderzh/coderzh.github.io.git
  4. git add -A
  5. git commit -m "first commit"
  6. git push -u origin master

配置

  1. baseURL = "https://blog.luning.wang/"
  2. languageCode = "en-us"
  3. title = "天问"
  4. [params]
  5. description = "个人博客

单篇文章配置

  1. ---
  2. # 常用定义
  3. title: "An Example Post" # 标题
  4. date: 2018-01-01T16:01:23+08:00 # 创建时间
  5. lastmod: 2018-01-02T16:01:23+08:00 # 最后修改时间
  6. draft: false # 是否是草稿?
  7. tags: ["tag-1", "tag-2", "tag-3"] # 标签
  8. categories: ["index"] # 分类
  9. author: "xianmin" # 作者
  10. # 用户自定义
  11. # 你可以选择 关闭(false) 或者 打开(true) 以下选项
  12. comment: false # 关闭评论
  13. toc: false # 关闭文章目录
  14. # 你同样可以自定义文章的版权规则
  15. contentCopyright: '<a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a>'
  16. reward: false # 关闭打赏
  17. mathjax: true # 打开 mathjax
  18. ---

Git管理博客实践

基本方法:dev分支存原始项目文件,master分支存public目录文件。
.gitignore

  1. public/