安裝主題後預覽網站出現類似錯誤訊息:

$ hugo server
Start building sites …
hugo v0.92.2+extended linux/amd64 BuildDate=2023-01-31T11:11:57Z VendorInfo=ubuntu:0.92.2-1ubuntu0.1
ERROR 2024/08/17 18:34:40 render of "page" failed: "/home/peel/files/blog/themes/typo/layouts/_default/baseof.html:2:18": execute of template failed: template: _default/single.html:2:18: executing "_default/single.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2024/08/17 18:34:40 render of "taxonomy" failed: "/home/peel/files/blog/themes/typo/layouts/_default/baseof.html:2:18": execute of template failed: template: _default/list.html:2:18: executing "_default/list.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2024/08/17 18:34:40 render of "page" failed: "/home/peel/files/blog/themes/typo/layouts/_default/baseof.html:2:18": execute of template failed: template: _default/single.html:2:18: executing "_default/single.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
ERROR 2024/08/17 18:34:40 render of "section" failed: "/home/peel/files/blog/themes/typo/layouts/_default/baseof.html:2:18": execute of template failed: template: _default/list.html:2:18: executing "_default/list.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
Error: Error building site: failed to render pages: render of "home" failed: "/home/peel/files/blog/themes/typo/layouts/_default/baseof.html:2:18": execute of template failed: template: _default/home.html:2:18: executing "_default/home.html" at <site>: can't evaluate field LanguageCode in type *langs.Language
Built in 62 ms

通常是 Hugo 版本太舊,如果透過 apt 更新,它的版本可能不是最新的。

hugo is already the newest version (0.92.2-1ubuntu0.1). 最新版本 0.92.2

$ sudo apt update
$ sudo apt install hugo
Reading package lists... Done
Building dependency tree... Done
Reading state information... Done
hugo is already the newest version (0.92.2-1ubuntu0.1).

前往 Hugo Github 確認版本,此時 Hugo 版本已經到 0.132.2

Hugo_Github_Release

GitHub Releases 下載最新的版本,如果是 Ubuntu 系統的話,請下載類似檔案名:hugo_0.132.2_Linux-64bit.tar.gz

解壓縮並輸入指令替換原本的舊版本:

tar -zxvf hugo_extended_0.xx.x_Linux-64bit.tar.gz
sudo mv hugo /usr/local/bin/

輸入 hugo version 檢查版本,確認更新成功。

$ hugo version
hugo v0.132.2-3fd26c70dff5934ec1802b9563530130ed1bca75 linux/amd64 BuildDate=2024-08-14T16:17:21Z VendorInfo=gohugoio

最後輸入 hugo server 就不會報錯了。

$ hugo server
Watching for changes in /home/peel/files/blog/{archetypes,content,data,layouts,static,themes}
Watching for config changes in /home/peel/files/blog/config.toml, /home/peel/files/blog/themes/typo/hugo.toml
Start building sites …
hugo v0.132.2-3fd26c70dff5934ec1802b9563530130ed1bca75 linux/amd64 BuildDate=2024-08-14T16:17:21Z VendorInfo=gohugoio


                   | EN
-------------------+-----
  Pages            | 12
  Paginator pages  |  0
  Non-page files   |  0
  Static files     | 12
  Processed images |  0
  Aliases          |  4
  Cleaned          |  0

Built in 88 ms
Environment: "development"
Serving pages from disk
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

附錄

Hugo 官網

Github Hugo Releases