Hugo是由Go语言实现的静态网站生成器。简单、易用、高效、易扩展、快速部署。java
<section>git
到 Hugo Releases 下载对应的操做系统版本的Hugo二进制文件(hugo或者hugo.exe)github
Mac下直接使用 Homebrew
安装:golang
brew install hugo
源码编译安装,首先安装好依赖的工具:json
设置好 GOPATH
环境变量,获取源码并编译:网站
$ export GOPATH=$HOME/go $ go get -v github.com/spf13/hugo
源码会下载到 $GOPATH/src
目录,二进制在 $GOPATH/bin/
ui
若是须要更新全部Hugo的依赖库,增长 -u
参数:
$ go get -u -v github.com/spf13/hugo
使用Hugo快速生成站点,好比但愿生成到 /path/to/site
路径:
$ hugo new site /path/to/site
这样就在 /path/to/site
目录里生成了初始站点,进去目录:
$ cd /path/to/site
站点目录结构:
▸ archetypes/ ▸ content/ ▸ layouts/ ▸ static/ config.toml
建立一个 about
页面:
$ hugo new about.md
about.md
自动生成到了 content/about.md
,打开 about.md
看下:
+++ date = "2015-10-25T08:36:54-07:00" draft = true title = "about" +++ 正文内容
内容是 Markdown
格式的,+++
之间的内容是 TOML 格式的,根据你的喜爱,你能够换成 YAML 格式(使用 ---
标记)或者 JSON 格式。
建立第一篇文章,放到 post
目录,方便以后生成聚合页面。
$ hugo new post/first.md
打开编辑 post/first.md
:
--- date: "2015-10-25T08:36:54-07:00" title: "first" --- ### Hello Hugo 1. aaa 1. bbb 1. ccc
到 皮肤列表 挑选一个心仪的皮肤,好比你以为 Hyde
皮肤不错,找到相关的 GitHub
地址,建立目录 themes
,在 themes
目录里把皮肤 git clone
下来:
# 建立 themes 目录 $ cd themes $ git clone https://github.com/spf13/hyde.git
在你的站点根目录执行 Hugo
命令进行调试:
$ hugo server --theme=hyde --buildDrafts --watch
使用 --watch
参数能够在修改文章内容时让浏览器自动刷新。
浏览器里打开: http://localhost:1313
假设你须要部署在 GitHub Pages
上,首先在GitHub上建立一个Repository,命名为:coderzh.github.io
(coderzh替换为你的github用户名)。
在站点根目录执行 Hugo
命令生成最终页面:
$ hugo --theme=hyde --baseUrl="http://coderzh.github.io/"
若是一切顺利,全部静态页面都会生成到 public
目录,将pubilc目录里全部文件 push
到刚建立的Repository的 master
分支。
$ cd public $ git init $ git remote add origin https://github.com/coderzh/coderzh.github.io.git $ git add -A $ git commit -m "first commit" $ git push -u origin master
浏览器里访问:http://coderzh.github.io/
这个网站 java union 就是我使用hugo生成的。 这个网站模板是我本身写的(样式部分除外),你们若是有关于hugo的以及go 模板相关的问题能够问我。