Hugo介绍及安装使用
Hugo介绍
The world’s fastest framework for building websites
Hugo 是世界上最快的构建网站的框架
Hugo 是最流行的开源静态站点生成器之一。凭借其惊人的速度和灵活性,Hugo 让搭建网站再次变得有趣。
英文官网:
https://gohugo.io/
Hugo主题:
https://themes.gohugo.io/
Hugo快速入门
第一步:安装 Hugo
macOS安装命令:
brew install hugo
hugo version
Windows版本安装:
下载地址:https://github.com/gohugoio/hugo/releases
下载Hugo Window版本:hugo_0.103.1_windows-amd64
解压之后配置环境变量(Path环境变量中添加hugo主目录):
设置--高级系统设置--环境变量--系统变量中,双击Path环境变量,在弹窗中点击新建按钮添加hugo主目录保存即可。
本例中hugo主目录为:D:\tools\hugo_0.103.1_windows-amd64
然后,在cmd中,输入hugo version查看版本号。
C:\Users\whwtr>hugo version
hugo v0.103.1-b665f1e8f16bf043b9d3c087a60866159d71b48d windows/amd64 BuildDate=2022-09-18T13:19:01Z VendorInfo=gohugoio
C:\Users\whwtr>
如上所示能正常显示版本号,即表示hugo安装成功。
下面开始我们的第一个hugo博客。
第二步:创建quickstart站点
创建站点命令:
hugo new site quickstart
D:\test02>hugo new site quickstart
Congratulations! Your new Hugo site is created in D:\test02\quickstart.
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.
D:\test02>cd quickstart
可以看到quickstart站点的目录结构:
|-quickstart
|-archetypes
|-content
|-data
|-layouts
|-public
|-static
|-themes
|-config.toml
第三步:添加ananke主题
下载主题并添加至站点theme目录:
cd quickstart
git init
git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
将主题添加到站点配置文件:
echo "theme = 'ananke'" >> config.toml
第四步:添加内容
在content目录下,创建posts/my-first-post.md文件,文件内容为:
---
title: "My First Post"
date: 2019-03-26T08:47:11+01:00
draft: true
---
第五步:启动Hugo服务
D:\test02\quickstart>hugo server -D
Start building sites …
hugo v0.103.1-b665f1e8f16bf043b9d3c087a60866159d71b48d windows/amd64 BuildDate=2022-09-18T13:19:01Z VendorInfo=gohugoio
| EN
-------------------+-----
Pages | 11
Paginator pages | 0
Non-page files | 0
Static files | 1
Processed images | 0
Aliases | 1
Sitemaps | 1
Cleaned | 0
Built in 49 ms
Watching for changes in D:\test02\quickstart\{archetypes,content,data,layouts,static,themes}
Watching for config changes in D:\test02\quickstart\config.toml, D:\test02\quickstart\themes\ananke\config.yaml
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
启动后,根据提示访问地址:http://localhost:1313/ 即可查看博客网页,如下图示:
可以根据自己的喜好,在主题官网上选择自己喜欢的主题,也可以根据官网文档自定义主题。
Hugo常用命令:
创建站点:
hugo new site quickstart
启动Hugo服务器
hugo server -D
构建静态页面
hugo -D
快速入门官方文档:
https://www.gohugo.cn/getting-started/installing/
(完)