目錄

Hugo 與 DoIt 主題設定

hugo new site my-blog
cd my-blog
git init
# Hugo default output directory
/public/
/resources/_gen/
/assets/jsconfig.json
hugo_stats.json

# Executable may be added to repository
hugo.exe
hugo.darwin
hugo.linux

# Temporary lock file while building
/.hugo_build.lock

# OS generated files
.DS_Store
.DS_Store?
._*
.Spotlight-V100
.Trashes
ehthumbs.db
Thumbs.db

# IDE/Editor files
.idea/
.vscode/
*.swp
*.swo

# Logs
*.log

在 hugo 目錄下執行

git submodule add https://github.com/HEIGE-PCloud/DoIt.git themes/DoIt
  1. 這個指令會:
  • 在你的 hugo repo 的 themes/DoIt 下載 DoIt 主題
  • 建立一個 .gitmodules 檔案來追蹤主題的來源
  • 但不會直接把主題的程式碼加入你的 repo
  1. .gitmodules 檔案會長得像這樣:
[submodule "themes/DoIt"]
path = themes/DoIt
url = https://github.com/HEIGE-PCloud/DoIt.git

這樣做的好處是:

  • 主題維持獨立,容易更新到最新版
  • 你的 repo 不會因為包含主題而變得很大
  • 可以追蹤使用主題的具體版本

在 hugo 網站根目錄下執行

git submodule update --remote --merge themes/DoIt
baseURL = "https://你的網站網址/"
# 語言設定
languageCode = "zh-tw"
defaultContentLanguage = "zh-tw"
# 網站標題
title = "你的網站名稱"
# 使用 DoIt 主題
theme = "DoIt"

# 顯示文章的字數統計、預計閱讀時間等
enableEmoji = true
enableRobotsTXT = true
enableGitInfo = true

# 文章設定
[params]
# 網站描述
description = "你的網站描述"
# 網站關鍵字
keywords = ["Blog", "Hugo", "DoIt"]

# 網站預設主題 ("auto", "light", "dark")
defaultTheme = "auto"

# 目錄設定
[params.page.toc]
# 是否開啟目錄
enable = true
# 是否保持開啟
keepStatic = false
# 是否自動顯示目錄
auto = true

# 程式碼高亮
[params.page.code]
copy = true
maxShownLines = 50

# 搜尋功能
[params.search]
enable = true
type = "lunr"

# 文章設定
[params.page]
# 是否顯示作者
author = true
# 是否顯示日期
date = true
# 是否顯示分類
categories = true
# 是否顯示標籤
tags = true

# 選單設定
[menu]
  [[menu.main]]
    identifier = "posts"
    name = "文章"
    url = "/posts/"
    weight = 1
  [[menu.main]]
    identifier = "categories"
    name = "分類"
    url = "/categories/"
    weight = 2
  [[menu.main]]
    identifier = "tags"
    name = "標籤"
    url = "/tags/"
    weight = 3
  [[menu.main]]
    identifier = "about"
    name = "關於"
    url = "/about/"
    weight = 4
---
title: "文章標題"
date: 2024-01-01T10:00:00+08:00
tags: ["tag1", "tag2"]
categories: ["cat1"]
---

archetypes/posts.md 建立你的文章模板

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
lastmod: {{ .Date }}
draft: true
author: "你的名字"
authorLink: ""
description: ""
license: ""
images: []

tags: []
categories: []

featuredImage: ""
featuredImagePreview: ""

hiddenFromHomePage: false
hiddenFromSearch: false
twemoji: false
lightgallery: true
ruby: true
fraction: true
fontawesome: true
linkToMarkdown: true
rssFullText: false
---

建立新文章

hugo new posts/我的新文章.md

在 Zettlr 或 vscode 寫好文章後,先本地預覽

hugo server -D

沒問題就發佈出去:

git add . ; git commit -m "commit說明"; git push -u origin main