Hugo教學筆記

教學影片清單: https://youtube.com/playlist?list=PLLAZ4kZ9dFpOnyRlyS-liKL5ReHDcj4G3
作者: Mike Dane

建立初始部落格

  1. 創建新blog
  2. hugo new site 指定資料夾
  3. 下載教學模版
    https://github.com/giraffeacademy/ga-hugo-theme
  4. cd 指定資料夾
    git clone https://github.com/giraffeacademy/ga-hugo-theme.git themes/ga-hugo-theme
  5. 至根目錄config.toml加入
  6. theme = "ga-hugo-theme"

Hugo結構解說

  • archetypes - define data about the content
  • content - 文章內容資料夾
  • data - 類似content資料夾 但存放語法、掛件等檔案
  • layouts - 網站外觀設定,如header, footer
  • static - 存放所有靜態元件(static element),比方說不會順應各頁面改變的物件(?)
  • themes - 現成套用佈景主題庫
  • confit.toml - 選項(settings)

基礎應用

List content

  • ! 在content資料夾建立測試文件時,發現使用hexo time stamp生成之時間會讓文件無法被render, 原因不明。修改時間後就恢復正常。
  • ! md文章可直接放在content資料夾,而content中之第一級資料夾(posts)如果包含任何md文章, 資料夾連結也會出現在測試主題的首頁。

_index.md

Hugo 只會自動為content下一級的資料夾文章生成連結,兩級以上資料夾中的內容無法自動顯示在list上。 解決方式為在兩級以上資料夾中創建_index.md

Front matter

Hugo的fm只接受三種語言:YAML, TOML, JSON
YAML範例:

title: A
date: 2020-12-23 21:15:50
draft: true # 好像不打也沒差
author: AAA
language: English
tags: ["tag1", "tag2"]
catagories: ["cat1"]

Archetypes

archetypes/default.md:每篇文章的預設值

---
title: "{{ replace .Name "-" " " | title }}"
date: {{ .Date }}
draft: true # 預設文章為草稿
author: Mike # 預設作者為Mike
---

! 這邊的設定會套用到所有文章,不過不知為啥怎麼測都沒用
! 若在archetypes資料夾中建立名為dir1.md文件,並加入front matter,hugo會自動在content中搜尋檔名或資料夾同為dir1的文件並覆蓋其fm內容

Shortcodes