Hugo的安装、博客站点创建、博文生成、本地化调试。


Hugo在macOS下的安装

安装包管理工具brew

1
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

使用brew安装Hugo

1
brew install hugo

更多请参考官网:https://brew.sh/index_zh-cn

初始化Hugo站点

在当前目录下生成站点

1
hugo new site myhugo

如果出现如下提示即生成成功:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
Congratulations! Your new Hugo site is created in /Users/lzwang/myhugo.

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.

生成博文

进入博客文件夹:

1
cd myhugo

注意:以下的操作均在根目录myhugo下进行。

生成一个about的静态页面

1
hugo new about.md

生成一篇新的名为myfirst的博文

1
hugo new post/myfirst.md

安装主题

1
2
3
cd themes
git clone https://github.com/spf13/hyde.git
cd ..

注意:下载完主题后,请参考每个主题的readme修改博客的config.toml文件,避免下面的指令每一次都添加参数。

编译

1
hugo

显示信息:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
Start building sites … 
                   | EN
-------------------+-----
  Pages            |  3
  Paginator pages  |  0
  Non-page files   |  1
  Static files     |  0
  Processed images |  0
  Aliases          |  0
  Sitemaps         |  1
  Cleaned          |  0

Total in 7 ms

本地化调试

1
hugo server

输出如下:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
Start building sites … 
                   | EN
-------------------+-----
  Pages            |  3
  Paginator pages  |  0
  Non-page files   |  1
  Static files     |  0
  Processed images |  0
  Aliases          |  0
  Sitemaps         |  1
  Cleaned          |  0

Built in 1 ms
Watching for changes in /Users/lzwang/myhugo/{archetypes,content,data,layouts,static}
Watching for config changes in /Users/lzwang/myhugo/config.toml
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:62236/ (bind address 127.0.0.1)
Press Ctrl+C to stop

参考资料

  1. Hugo官网:https://gohugo.io/
  2. Hugo主题:https://www.gohugo.org/theme/
  3. Hugo中文文档:https://www.gohugo.org/
  4. 使用Hugo生成静态博客教程:https://sb.sb/blog/migrate-to-hugo/