個人環境是使用MacOS
安裝Hugo
brew install hugo
建立網誌專案
hugo new site demo
在本機啟動
hugo server -D
可以看到啟動後空空如也,這時候可以去Hugo Themes選取喜歡的Theme,
我自己是選擇LoveIt,有不錯的文件說明還有中文註釋,對於想簡單架設的我來說很適合,作者提供了幾種做法可以安裝theme,
直接下載zip並在themes/ 資料夾中解壓縮
或是使用
git clone https://github.com/dillonzq/LoveIt.git themes/LoveIt
我自己是因為要上傳到github pages所以使用
git init
git submodule add https://github.com/dillonzq/LoveIt.git themes/LoveIt
安裝好Theme後需要在config.toml中指定使用的theme是什麼
baseURL = 'http://example.org/'languageCode = 'en-us' title = 'My New Hugo Site' theme = 'Loveit'
修改好後再重新啟動hugo就可以看到Theme已經好了
再來就可以開始修改Theme把他改造成自己喜歡的模樣了!
專案目錄下的config.toml是全局的config,如果要修改局部的就要到themes/LoveIt/config.toml中修改,主要的設定說明config都有註解,我就提一些我自己有做的修改,首先是作者配置
再來是底部的文字,修改themes/LoveIt/config.toml
# Footer config# 页面底部信息配置[params.footer]enable = true# Custom content (HTML format is supported)# 自定义内容 (支持 HTML 格式)custom = "Powered by Demo"# whether to show Hugo and theme info# 是否显示 Hugo 和主题信息hugo = false# whether to show copyright info# 是否显示版权信息copyright = true# whether to show the author# 是否显示作者author = true# site creation time# 网站创立年份since = 2022# ICP info only in China (HTML format is supported)# ICP 备案信息,仅在中国使用 (支持 HTML 格式)icp = ""# license info (HTML format is supported)# 许可协议信息 (支持 HTML 格式)license= ""
儲存後就會看網站下方已經改變了
再來是更新網站title和中間的文字
全局config.toml
title = 'This is demo site'
themes/LoveIt/config.toml
# Header config# 页面头部导航栏配置[params.header]# title name# 标题名称name = "My demo site"# Home page config# 主页信息设置[params.home]# 主页显示的网站副标题 (允许 HTML 格式)subtitle = "This is my demo site"
再來就是如何設置menu,假設要設置三個目錄並支援中英文語系切換
全局config.toml
[languages][languages.zh-tw]weight = 1title = "展示"languageCode = "zh-TW"languageName = "繁體中文"hasCJKLanguage = true[[languages.zh-tw.menu.main]]weight = 1identifier = "demo1"pre = ""post = ""name = "展示1"url = "/demo1/"title = ""[[languages.zh-tw.menu.main]]weight = 2identifier = "demo2"pre = ""post = ""name = "展示2"url = "/demo2/"title = ""[[languages.zh-tw.menu.main]]weight = 3identifier = "demo3"pre = ""post = ""name = "展示3"url = "/demo3/"title = ""[languages.en]weight = 2title = "Demo"languageCode = "en"languageName = "English"[[languages.en.menu.main]]weight = 1identifier = "demo1"pre = ""post = ""name = "Demo1"url = "/demo1/"title = ""[[languages.en.menu.main]]weight = 2identifier = "demo2"pre = ""post = ""name = "Demo2"url = "/demo2/"title = ""[[languages.en.menu.main]]weight = 3identifier = "demo3"pre = ""post = ""name = "Demo3"url = "/demo3/"title = ""
簡單的設置一下就可以開始寫文章了,
新增文章可以使用hugo 指令也可以自己新增.md
由於我們有用雙語系,所以同一個文章要產生對應雙語言
hugo new demo1/demo1.en.md
hugo new demo1/demo1.zh-tw.md
hugo new demo2/demo2.en.md
hugo new demo2/demo2.zh-tw.md
hugo new demo3/demo3.en.md
hugo new demo3/demo3.zh-tw.md