Franky's Blog

书山有路勤为径,学海无涯苦作舟……

Hugo-Quick Start

第一篇博文…

创建网站

[root@itfranky franky]# hugo new site path/to/yoursite

 1
 2[root@itfranky app]# cd /app/
 3[root@itfranky app]# hugo new site franky
 4Congratulations! Your new Hugo site is created in /app/franky.
 5
 6Just a few more steps and you're ready to go:
 7
 81. Download a theme into the same-named folder.
 9   Choose a theme from https://themes.gohugo.io/, or
10   create your own with the "hugo new theme <THEMENAME>" command.
112. Perhaps you want to add some content. You can add single files
12   with "hugo new <SECTIONNAME>/<FILENAME>.<FORMAT>".
133. Start the built-in live server via "hugo server".
14
15Visit https://gohugo.io/ for quickstart guide and full documentation.
16

网站目录(skeleton)

 1
 2[root@itfranky app]# ll franky/
 3total 28
 4drwxr-xr-x 2 root root 4096 Jan 13 11:13 archetypes
 5-rw-r--r-- 1 root root   82 Jan 13 11:13 config.toml
 6drwxr-xr-x 2 root root 4096 Jan 13 11:13 content
 7drwxr-xr-x 2 root root 4096 Jan 13 11:13 data
 8drwxr-xr-x 2 root root 4096 Jan 13 11:13 layouts
 9drwxr-xr-x 2 root root 4096 Jan 13 11:13 static
10drwxr-xr-x 2 root root 4096 Jan 13 11:13 themes
11[root@itfranky app]# 
12

config.toml是hugo网站的配置文件,所有的全局配置都要放在这个文件中。

使用主题

1[root@itfranky franky]# cd themes/
2[root@itfranky themes]# 
3[root@itfranky themes]# git clone https://github.com/alanorth/hugo-theme-bootstrap4-blog.git bootstrap4
4

Before you use a theme, remove the .git folder in that theme’s root folder. Otherwise, this will cause problem if you deploy using Git.

1[root@itfranky themes]# cd bootstrap4/
2[root@itfranky bootstrap4]# rm -rf .git

修改config文件,使用主题推荐的config.toml

1[root@itfranky bootstrap4]# cp exampleSite/config.toml /app/franky/
2cp: overwrite `/app/franky/config.toml'? y
3[root@itfranky bootstrap4]#

修改config文件,其他配置参数根据自己的要求来修改。

1baseurl = "http://这里是你的域名/"
2theme = "bootstrap4"

The themename in the above examples must match the name of the specific theme directory inside /themes; i.e. the directory name (likely lowercase and urlized) rather than the name of the theme displayed in the Themes Showcase site.

第一篇文章

[root@itfranky franky]# hugo new post/go-install.md

1[root@itfranky franky]# hugo new post/go-install.md
2/app/franky/content/post/go-install.md created
3[root@itfranky franky]# tree content/
4content/
5└── post
6    └── go-install.md
7
81 directory, 1 file
9[root@itfranky franky]# 

可以看到在content/post/下产生了一个go-install.md文件,在文件上面可以看到这么几行:

1 ---
2 title: "Go Install"
3 date: 2018-01-13T14:36:43+08:00
4 draft = true
5 ---

单篇博客的配置在---内配置。我安装的Hugo生成的文件是---,也有+++的,可以修改archetypes/default.md指定,其中的区别参见Hugo文档Content Management/Front Matter

其中title就是博客的标题,draft=true表示这是一篇草稿,Hugo默认是不会渲染草稿状态的博客的,完成博客后使用命令:

[root@itfranky franky]# hugo undraft content/post/go-install.md

可以改变博客的draft状态,或者手动到文件中修改。然后在—区域下面添加内容。

网站发布

在项目根目录下执行hugo

 1[root@itfranky franky]# hugo
 2
 3                   | EN  
 4+------------------+----+
 5  Pages            |  7  
 6  Paginator pages  |  0  
 7  Non-page files   |  0  
 8  Static files     |  9  
 9  Processed images |  0  
10  Aliases          |  2 
11  Sitemaps         |  1  
12  Cleaned          |  0  
13
14Total in 26 ms
15[root@itfranky franky]# 
16[root@itfranky franky]# ll public/
17total 48
18drwxr-xr-x 3 root root 4096 Jan 13 14:36 2018
19drwxr-xr-x 2 root root 4096 Jan 13 13:09 categories
20drwxr-xr-x 2 root root 4096 Jan 13 12:12 css
21drwxr-xr-x 2 root root 4096 Jan 13 12:12 fonts
22-rw-r--r-- 1 root root 5275 Jan 13 15:02 index.html
23-rw-r--r-- 1 root root 2340 Jan 13 15:02 index.xml
24drwxr-xr-x 2 root root 4096 Jan 13 12:12 js
25drwxr-xr-x 3 root root 4096 Jan 13 13:09 page
26drwxr-xr-x 3 root root 4096 Jan 13 14:36 post
27-rw-r--r-- 1 root root  770 Jan 13 15:02 sitemap.xml
28drwxr-xr-x 2 root root 4096 Jan 13 13:09 tags
29[root@itfranky franky]# 

Hugo会把我们的项目打包在一个public文件夹中,因为是静态的网站,所以只需要把public目录复制到服务器上。


Share