Hugo -最好用的靜態網站生成器

Hugo是由Go語言實現的靜態網站生成器。簡單、易用、高效、易擴展、快速部署。java

快速開始

<section>git

安裝Hugo

1\. 二進制安裝(推薦:簡單、快速)

Hugo Releases 下載對應的操做系統版本的Hugo二進制文件(hugo或者hugo.exe)github

Mac下直接使用 Homebrew 安裝:golang

brew install hugo

2\. 源碼安裝

源碼編譯安裝,首先安裝好依賴的工具: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 命令進行調試:

$ 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 模板相關的問題能夠問我。

相關文章
相關標籤/搜索