安装 Hugo 并建立站点

按以下步骤建立站点 blog 并使用飞雪无情的 maupassant 主题(感谢),在浏览器中输入 http://localhost:1313 查看新创建站点。

brew install hugo
hugo new site blog

cd blog
git init
git clone https://github.com/rujews/maupassant-hugo themes/maupassant

hugo new post/my-first-post.md
hugo server -D

自定义菜单

在 config.toml 配置文件中新增:

[menu]
  [[menu.main]]
    identifier = "research"
    name = "研究"
    url = "/research/"
    weight = 2
  [[menu.main]]
    identifier = "archives"
    name = "归档"
    url = "/archives/"
    weight = 3
  [[menu.main]]
    identifier = "about"
    name = "关于"
    url = "/about/"
    weight = 4

增加文章归档支持

新建 content/archives/index.md 文件,内容如下:

title: "归档"
description: 文章归档
type: archives

永久链接

在每篇文章里的 Front Matter 加上:

url: /yyyy/mm/dd/post-title.html

大小写问题

为保持原来的大小写,而不自动转小写,可在 config.toml 配置文件中新增:

preserveTaxonomyNames = true
disablePathToLower = true

文章转移

将原 Hexo 文章(Markdown 格式)转移至 /content/post/ 文件夹,相关插图转移至 /static/ 文件夹下,图片引用格式为:

![Alt_Name](/rsc/post_title/1.jpg)

新建 GitHub Pages

新建 GitHub 仓库 hcgu.github.io,不要初始化,地址为 git@github.com:hcgu/hcgu.github.io.git。在 public 文件夹内:

git init
git remote add origin git@github.com:hcgu/hcgu.github.io.git

生成静态页并发布

在 blog 目录下使用命令 hugo 生成静态页,存储于 public 文件夹,进入该文件夹:

git add .
git commit -m "Updated at $(date)."
git push -u origin master