使用 Hugo 搭建我的博客

0. Hugo 簡介

官網:Hugolinux

1. 安裝 Hugo

ArchLinux爲例:git

$ sudo pacman -S hugo
...
$ hugo version  # 驗證安裝
Hugo Static Site Generator v0.54.0/extended linux/amd64 BuildDate: unknown
複製代碼

其餘操做系統請參考:Installing Hugogithub

2. 建立網站

$ hugo new site quickstart
Congratulations! Your new Hugo site is created in /xxx/xxx/quickstart.

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. 複製代碼

3. 添加一個主題

所有主題見themes.gohugo.io,這裏以Ananke主題爲例:bash

$ cd quickstart
$ git init
$ git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke
$ cat config.toml
baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
$ echo 'theme = "ananke"' >> config.toml
$ cat config.toml
baseURL = "http://example.org/"
languageCode = "en-us"
title = "My New Hugo Site"
theme = "ananke"
複製代碼

4. 添加一些內容

$ hugo new posts/my-first-post.md
複製代碼

而後在my-first-post.md中任意添加一些內容。ide

5. 啓動 Hugo 服務

$ hugo server -D

                   | EN  
+------------------+----+
  Pages            | 10  
  Paginator pages  |  0  
  Non-page files   |  0  
  Static files     |  3  
  Processed images |  0  
  Aliases          |  1  
  Sitemaps         |  1  
  Cleaned          |  0  

Total in 12 ms
Watching for changes in /home/ronald/go/src/quickstart/{content,data,layouts,static,themes}
Watching for config changes in /home/ronald/go/src/quickstart/config.toml
Environment: "development"
Serving pages from memory
Running in Fast Render Mode. For full rebuilds on change: hugo server --disableFastRender
Web Server is available at http://localhost:1313/ (bind address 127.0.0.1)
Press Ctrl+C to stop
複製代碼

而後打開http://localhost:1313/訪問。post

6. 自定義主題

詳情請參考Theme Components網站

-1. 遷移

先把blog倉庫克隆下來,而後刪除此倉庫並重建此倉庫,而後換一個目錄將此倉庫再克隆下來,而後講原倉庫的文件所有複製進新倉庫。ui

而後:spa

$ cd blog
$ git submodule add https://github.com/aubm/hugo-code-editor-theme.git themes/code-editor
$ git submodule add -b master git@github.com:RonaldZhao/RonaldZhao.github.io.git public
複製代碼

而後將public文件夾中除.git文件外所有刪除,而後在blog文件夾中執行hugo -D操作系統

最後分別在blogpublic文件夾中push

相關文章
相關標籤/搜索