使用hugo建立静态个人网站

Mar 13, 2021

4 mins read

安装Hugo

Hugo程序可以从这里下载

Windows建议下载hugo_extended_0.81.0_Windows-64bit.zip,其他系统可下载对应版本。

另,CentOS安装hugo可参考此文

使用hugo

首先使用hugo new test来建立新的站点。

$ hugo new site test
Congratulations! Your new Hugo site is created in D:\test.

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/,按需挑选主题下载下来放到themes目录,以下以compose为例。

$cd test/themes/  #进入主题目录
$ git clone https://hub.fastgit.org/onweru/compose.git  #下载compose主题
Cloning into 'compose'...
remote: Enumerating objects: 53, done.
remote: Counting objects: 100% (53/53), done.
remote: Compressing objects: 100% (39/39), done.
remote: Total 2567 (delta 26), reused 35 (delta 13), pack-reused 2514
Receiving objects: 100% (2567/2567), 6.84 MiB | 463.00 KiB/s, done.
Resolving deltas: 100% (1362/1362), done.

$ rm -rf compose/.git*
$ cp themes/compose/exampleSite/config.toml ./  #将主体内的配置文件拷贝至网站根目录

然后编辑config.toml文件,加入theme = "compose"

接下来hugo server即可生成站点预览,浏览器进入http://localhost:1313即可浏览。

不过当前只有空站,没有任何文章。

$ hugo new content/new.md
content\new.md created

通过以上命令新增new.md文件即可。

编辑完文章后可以通过hugo命令来生成静态内容,生成的内容放在public文件夹下。

部署站点