Featured image of post Hugo使用教程

Hugo使用教程

Hugo使用学习过程记录

什么是Hugo

Hugo是用go语言编写的静态网站生成器,不同于动态网站,静态网站不能和用户进行交互,没有数据库系统,所有页面都是静态的html文件,静态网站通常具有更高的访问速度和安全性,但是不能实现复杂的交互功能,如果只是页面展示,如博客,公司页面,可以使用hugo来生产静态网站,本博客就是使用hugo生成的。

hugo的安装

版本

hugo有两种版本,基础版和扩展版本,建议安装扩展版本,extend

前提条件:

  • 安装git
  • 安装go环境

前面的前提条件准备好后,就可以安装hugo了,本文以ubuntu系统为例子: Alt text
找到版本102.3 Alt text 复制链接下载安装包

1
wget https://github.com/gohugoio/hugo/releases/download/v0.102.3/hugo_extended_0.102.3_Linux-64bit.deb

执行

1
2
sudo apt update apt install dpkg
sudo dpkg -i hugo_0.121.2_linux-amd64.deb

输出hugo的版本信息

1
2
asdxet@asdxet:~/website$ hugo version
hugo v0.102.3-b76146b129d7caa52417f8e914fc5b9271bf56fc+extended linux/amd64 BuildDate=2022-09-01T10:16:19Z VendorInfo=gohugoio

如果看到这个说明hugo已经安装成功了

创建网站

使用如下命令创建一个网站

1
2
hugo new site website
cd website

安装主题 hugo-theme-stack

1
git clone https://github.com/CaiJimmy/hugo-theme-stack/ themes/hugo-theme-stack

执行完毕后,在themes文件夹中就会有hugo-theme-stack这个主题了 进入themes/hugo-theme-stack/exampleSite 文件夹,将content文件夹和config.yaml文件复制到根目录

运行

回到根目录

1
hugo server

服务器将运行在1313端口

遇到的问题?

1
2
3
4
5

ERROR 2024/01/13 01:21:24 Failed to get JSON resource "https://publish.twitter.com/oembed?dnt=false&omit_script=true&url=https%3A%2F%2Ftwitter.com%2FDesignReviewed%2Fstatus%2F1085870671291310081": Get "https://publish.twitter.com/oembed?dnt=false&omit_script=true&url=https%3A%2F%2Ftwitter.com%2FDesignReviewed%2Fstatus%2F1085870671291310081": dial tcp 104.244.43.52:443: i/o timeout
If you feel that this should not be logged as an ERROR, you can ignore it by adding this to your site config:
ignoreErrors = ["error-remote-getjson"]
Error: Error building site: "/home/asdxet/website/content/post/rich-content/index.md:1:1": timed out initializing value. You may have a circular loop in a shortcode, or your site may have resources that take longer to build than the `timeout` limit in your Hugo config file.

如果出现这个错误, 删除rich-content/index.md下这两个选项即可

1
2
3
4
5
6
## Twitter Simple Shortcode

<br>
---

## Vimeo Simple Shortcode