如何使用 Hugo 模塊

在使用 Hugo 模塊前,你需要做一些準備工作。
本頁內容

安裝 Go

詳情請參閱 download and install Go

初始化

我們首先需要通過 hugo mod init MODULE_PATH 將你的網站或主題初始化為模塊。

MODULE_PATH 是網站或主題的標識符,其通常為不帶協議的倉庫地址,比如:

1hugo mod init example.com/user/repo

導入模塊

接著你就可以導入任意你需要的模塊了,舉個例子:

hugo.yaml

1module:
2  imports:
3  - path: github.com/hugomods/icons/vendors/bootstrap
4  - path: github.com/hugomods/images
5  - path: github.com/hugomods/bootstrap
6  - path: github.com/hugomods/katex

hugo.toml

1[module]
2  [[module.imports]]
3    path = 'github.com/hugomods/icons/vendors/bootstrap'
4  [[module.imports]]
5    path = 'github.com/hugomods/images'
6  [[module.imports]]
7    path = 'github.com/hugomods/bootstrap'
8  [[module.imports]]
9    path = 'github.com/hugomods/katex'

hugo.json

 1{
 2   "module": {
 3      "imports": [
 4         {
 5            "path": "github.com/hugomods/icons/vendors/bootstrap"
 6         },
 7         {
 8            "path": "github.com/hugomods/images"
 9         },
10         {
11            "path": "github.com/hugomods/bootstrap"
12         },
13         {
14            "path": "github.com/hugomods/katex"
15         }
16      ]
17   }
18}