Hugo 是用 Go 编程语言编写的静态网站生成器。它将 Markdown 文件和其他静态资源(如图片和样式表)转换为完整的静态网站。这些静态网站可以托管在任何提供静态文件托管的服务器上,如 GitHub Pages、Netlify、Vercel 等。hugo是一个开源的博客程序项目,github上有73K的star。 我们打开它的官网:https://gohugo.io/ 就可以看到。hugo号称世界上最快的网站建设框架。
教程采用二进制程序的方式来安装Hugo,基于Centos
wget https://github.com/gohugoio/hugo/releases/download/v0.127.0/hugo_0.127.0_linux-amd64.tar.gz
tar -zxvf hugo_0.127.0_linux-amd64.tar.gz -C /usr/local/bin/
hugo new site test
test可以改成你自己期望的目录名字。屏幕输出以下内容,则站点创建成功
Congratulations! Your new Hugo site was created in /hu/test.
Just a few more steps...
1. Change the current directory to /hu/test.
2. Create or install a theme:
- Create a new theme with the command "hugo new theme <THEMENAME>"
- Or, install a theme from https://themes.gohugo.io/
3. Edit hugo.toml, setting the "theme" property to the theme name.
4. Create new content with the command "hugo new content <SECTIONNAME>/<FILENAME>.<FORMAT>".
5. Start the embedded web server with the command "hugo server --buildDrafts".
See documentation at https://gohugo.io/.
cd /hu/test.
可以看到hugo生成的以下文件和目录。hugo.toml是站点的URL和语言设置信息,themes是主题。content是存放我们的内容的路径。 +++
title = 'Test'
date = 2024-06-19T19:09:16+08:00
draft = true
+++
# helloworld !
git clone https://github.com/spf13/hyde
hugo server
启动服务即可,(这里要注意的是我执行了hugo server 但是前台始终无法访问该站点,防火墙也已经打开了但是无法访问,最终执行了这个命令才好。
hugo server --bind="0.0.0.0"
)。hugo内置了一个web服务器,所以我们没有额外安装别的服务器,以及启动hugo 服务的时后的路径一定要在站点目录下面。执行完后,页面会输出 这样的内容。
Built in 16 ms Environment: "development" Serving pages from disk Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender Web Server is available at //XXXXX:1313/ (bind address 0.0.0.0) Press Ctrl+C to stop
我们去对应的端口访问即可。发现页面如下,大功告成!
有的同学可能会好奇,为什么这里没有看到我刚刚写的test.md的文章。是因为在test.md文章里,draft的值是默认为true。默认情况下,在构建站点时Hugo不发布草稿内容。如果你编辑完了,想看到这个文章,那么只需要把值改为false即可。
+++ title = ‘Test’ date = 2024-06-20T10:34:00+08:00 draft = false
+++