1. 程式人生 > >基於Hugo搭建個人Blog

基於Hugo搭建個人Blog

前言

hugo和hexo一樣,是靜態網站生成器,特點是基於Go語言編寫,部署高效快速。

安裝

  1. 解壓縮或者安裝後,將hugo.exe所在資料夾的目錄新增到系統環境變數Path下

  2. 驗證Hugo版本 hugo version

生成站點

建立靜態站點

# YourSiteName為你新建的站點資料夾名稱
$ hugo new site YourSiteName

新增Themes

$ cd YourSiteName/themes
$ git clone https://github.com/spf13/hyde.git

用下載主題裡的YourSiteName\themes\YourThemeName\exampleSite\config.toml

配置檔案替換根目錄下YourSiteName\config.toml檔案

設定config.toml裡屬性theme: "YourThemeName"

生成部落格

使用hugo new YourFileName.md命令生成頁面,預設放置在content目錄下。因為除了部落格的正文外還需要一些about頁面,此處採用hugo new post/YourFileName.md生成部落格正文頁面,在content目錄下生成二級目錄*/post*

---
title: "bolg name"      #此篇blog的標題
date: "2017-12-05"
draft: true				#false對外可見,true
僅對自己可見 tags: ["one"] #tags文件的標籤或關鍵字 categories: ["one"] #categories文件所屬分類 ---

這個頭部配置的資訊是和archetypes裡default.md的格式一樣,是可以改成自己想要的格式的

啟動服務

$ hugo server

託管到github

  1. 這個時候我們可以部署到 Github Pages,只需要在你自己的 github 裡面建立一個命名為YourGithubName.github.io的倉庫。

  2. 將根目錄下config.toml檔案中baseURL改為https://YourGithubName.github.io/

  3. 在站點根目錄執行hugo命令生成/public資料夾。public下存放的就是所有靜態頁面,只需要把public目錄裡面的檔案push到你的倉庫就好

cd public
$ git init
$ git remote add origin https://github.com/YourGithubName/YourGithubName.github.io.git
$ git add .
$ git commit -m "first commit"
$ git push -u origin master