How to Deploy a Hugo Blog

安装 Hugo

从Hugo的Github上面找到最新发布的windows安装包:https://github.com/gohugoio/hugo/releases.

安装完成之后,可以用下面的命令检查是否正确安装了Hugo:

hugo version

执行后如果出现 hugo v0.110.0-e32a493b7826d02763c3b79623952e625402b168 windows/amd64 BuildDate=2023-01-17T12:16:09Z VendorInfo=gohugoio 这样的字符串,说明安装成功。

创建站点

使用hugo new site [path] [flags]命令创建新站点,如:

$ hugo new site NewBlog
Congratulations! Your new Hugo site is created in PATH_TO_HugoSite/NewBlog.

Just a few more steps and you're ready to go:

1. Download a theme into the same-named folder.
   Choose a theme from https://themes.gohugo.io/ or
   create your own with the "hugo new theme <THEMENAME>" command.
2. Perhaps you want to add some content. You can add single files
   with "hugo new <SECTIONNAME>\<FILENAME>.<FORMAT>".
3. Start the built-in live server via "hugo server".

Visit https://gohugo.io/ for quickstart guide and full documentation.

添加主题

https://themes.gohugo.io/去挑选一个主题,点击Download,进入到对应主题的github页面。

进入到上述NewBlog路径下的themes路径,下载对应主题的Github代码仓。以terminal为例:

git clone https://github.com/panr/hugo-theme-terminal.git

下载完成之后,进入主题的exampleSite,将其中的config.toml文件内容复制到NewBlog路径下的config.toml文件中,并修改相应字段。

新增文章

使用hugo new [path] [flags]来创建文章。

如使用hugo new posts/FirstPost.md来创建第一篇Post,执行后,会在content目录下创建对应文件和文件夹,并生成对应模板。

---
title: "FirstPost"
date: 2023-04-08T15:37:40+08:00
draft: true
---

如果要发布,需要将draft状态修改为false

不同主题的字段及配置方法不尽相同,需要自行阅读对应主题的文档。

预览

执行hugo server,报了错:

Error: Error building site: TOCSS: failed to transform "css/base.scss" (text/x-scss). Check your Hugo installation; you need the extended version to build SCSS/SASS with transpiler set to 'libsass'.: this feature is not available in
 your current Hugo version, see https://goo.gl/YMrWcn for more information

解决方法是到对应链接下载带有extend字样的安装包。我使用choco安装了对应的版本:choco install hugo-extended

发布

先使用hugo命令构建,构建的结果在public目录中。将public目录的东西提交到网站即可。