準備
- 💊💊上課用模板
- 看看有沒有裝hugo 下載,安裝則看下圖
- 設定執行環境(在電腦教室直接解壓縮,我們只需要hugo.exe放在子目錄)
- 參考步驟節錄
hugo new site myweb #🏷️ cd myweb # 建立簡單範本 hugo new theme exampleTheme # 🏷️ # clone 別人的範本 #git submodule add https://github.com/gcushen/hugo-academic.git themes/academic git submodule add https://github.com/budparr/gohugo-theme-ananke.git themes/ananke #🏷️ echo theme = ananke >> config.toml # 🏷️ hugo new posts/my-first-post.md
自建立theme
layout/index.html
內容原本是空的,加入如下內容,可以把content/_index.md
的內容顯示
{{ .Content }}
- 'baseof.html`
<!DOCTYPE html> <html> {{- partial "head.html" . -}} <body> {{- block "main" . }} {{- end -}} </body> </html>
- list.html
{{ define "main" }} {{ .Content }} {{ range .RegularPages.ByTitle }} <a class="text-body" href="{{ .RelPermalink }}">{{ if .Draft }}DRAFT: {{end}}{{ .Title }}</a> {{- end -}} {{ end }}
- single.html
{{ define "main" }} {{ .Content }} {{ end }}
config.toml
config.toml 中
uglyURLs = true
以子目錄post
為例
- false
- 翻譯成
hostURL/post/
- 翻譯成
- true
- 翻譯成
hostURL/post.html
裡面的檔案,例如xx.md
- 翻譯成
- false
- 翻譯成
hostURL/post/xx
- 翻譯成
- true
- 翻譯成
hostURL/post/xx.html
- 翻譯成
常用hugo指令
# 輸出HTML
hugo
# 本地測試+草稿檔案
hugo server -D
# 建立網站
hugo new site
# 建立主題
hugo new theme exampleTheme
# 建立文件
hugo new path/to/file.md
# 列出內容
hugo list drafts
hugo list expired
hugo list future
# Garbage Collection, removes generate resources like resized images
hugo --gc
hugo server -D --navigateToChanged --watch --disableFastRender
文件panel
draft: true
expiryDate: 2018-05-04T12:30+01:00
# 文章會在這個日期之後不顯示,除非 hugo --buildExpired 選項。
publishDate: 2018-05-04T12:30+01:00
# 預設發布日期
複雜的theme
- 建立空的git repo(這裡https://github.com/airbone5/myweb.git)
- 建立根目錄和複製現有的theme
cd mytest hugo new site myweb cd myweb cd themes git clone https://github.com/matcornic/hugo-theme-learn.git
- 設定config.toml
baseURL = 'https://airbone5.github.io/myweb/' # 🏷️ languageCode = 'en-us' title = 'My New Hugo Site' theme = "hugo-theme-learn" #🏷️ publishDir = "docs" #🏷️
- 測試
..\hugo server #🏷️
- 推到自己的git repo
git init . git add . #❌😒 git add . # 🏷️ git push
- 但是這時候,還沒有網頁,只有原始檔案,因此到github setting裡面 設定網頁指向。(見課堂)
- 產生網頁
..\hugo
- 推到git repo
- done.
建立自己的主題
關鍵字: build hugo theme