Configure Hugo modules
模組配置:頂層
hugo.
module:
noProxy: none
noVendor: ""
private: '*.*'
proxy: direct
replacements: ""
vendorClosest: false
workspace: "off"
[module]
noProxy = 'none'
noVendor = ''
private = '*.*'
proxy = 'direct'
replacements = ''
vendorClosest = false
workspace = 'off'
{
"module": {
"noProxy": "none",
"noVendor": "",
"private": "*.*",
"proxy": "direct",
"replacements": "",
"vendorClosest": false,
"workspace": "off"
}
}
- noProxy
- (
string
) 以逗號分隔的 glob 列表,用於匹配不應使用上述配置代理的路徑。 - noVendor
- (
string
) 可選的 Glob 模式,用於匹配在 vendoring 時應跳過的模組路徑,例如 “github.com/**"。 - private
- (
string
) 以逗號分隔的 glob 列表,用於匹配應被視為私有的路徑。 - proxy
- (
string
) 定義下載遠端模組時使用的代理伺服器。預設為direct
,意味著使用 “git clone” 等類似方式。 - vendorClosest
- (
bool
) 啟用後,將選擇距離使用該模組最近的 vendored 模組。預設行為是選擇第一個。請注意,一個給定模組路徑仍只能有一個依賴,因此一旦使用便無法重新定義。預設為false
。 - workspace
- (
string
) 要使用的工作區檔案。這啟用了 Go 的工作區模式。此配置也可透過作業系統環境變數設定,例如export HUGO_MODULE_WORKSPACE=/my/hugo.work
。此功能僅在 Go 1.18+ 中有效。在 Hugov0.109.0
中,我們將預設值改為off
,並將相對的工作檔案名稱解析為相對於工作目錄的路徑。 - replacements
- (
string
) 一個用逗號分隔的模組路徑與目錄映射列表,例如github.com/bep/my-theme -> ../..,github.com/bep/shortcodes -> /some/path
。這主要用於模組的臨時本地開發,在這種情況下,您可能希望將其保存為環境變數,例如:env HUGO_MODULE_REPLACEMENTS="github.com/bep/my-theme -> ../.."
。相對路徑是相對於 themesDir。絕對路徑亦被允許。
上述設定的條款直接對應到 Go Modules 的相關選項。部分設定可能更適合作為作業系統環境變數設定。例如,要設定使用的代理伺服器:
env HUGO_MODULE_PROXY=https://proxy.example.org hugo
模組配置:hugoVersion
如果您的模組需要特定版本的 Hugo 才能正常運作,您可以在 module
區段中指明,當用戶使用過舊或過新的版本時,會收到警告。
hugo.
module:
hugoVersion:
extended: false
max: ""
min: ""
[module]
[module.hugoVersion]
extended = false
max = ''
min = ''
{
"module": {
"hugoVersion": {
"extended": false,
"max": "",
"min": ""
}
}
}
以上任一項可選擇省略。
- min
- (
string
) 支援的最低 Hugo 版本,例如0.55.0
。 - max
- (
string
) 支援的最高 Hugo 版本,例如0.55.0
。 - extended
- (
bool
) 是否需要 Hugo 的擴展版本。
模組配置:imports
hugo.
module:
imports:
- disable: false
ignoreConfig: false
ignoreImports: false
path: github.com/gohugoio/hugoTestModules1_linux/modh1_2_1v
- path: my-shortcodes
[module]
[[module.imports]]
disable = false
ignoreConfig = false
ignoreImports = false
path = 'github.com/gohugoio/hugoTestModules1_linux/modh1_2_1v'
[[module.imports]]
path = 'my-shortcodes'
{
"module": {
"imports": [
{
"disable": false,
"ignoreConfig": false,
"ignoreImports": false,
"path": "github.com/gohugoio/hugoTestModules1_linux/modh1_2_1v"
},
{
"path": "my-shortcodes"
}
]
}
}
- path
- 可以是有效的 Go Module 模組路徑,例如
github.com/gohugoio/myShortcodes
,或模組在您的主題資料夾中儲存的目錄名稱。 - ignoreConfig
- 如果啟用,則不會載入任何模組配置檔案,例如
hugo.toml
。請注意,這也會阻止載入任何間接模組依賴。 - ignoreImports
- 如果啟用,模組匯入將不會被跟隨。
- disable
- 設為
true
將停用模組,但保留任何go.*
檔案中的版本資訊。 - noMounts
- 不掛載此匯入中的任何資料夾。
- noVendor
- 從不為此匯入進行 vendoring(僅適用於主要專案)。
模組配置:mounts
預設掛載
hugo.
module:
mounts:
- source: content
target: content
- source: static
target: static
- source: layouts
target: layouts
- source: data
target: data
- source: assets
target: assets
- source: i18n
target: i18n
- source: archetypes
target: archetypes
[module]
[[module.mounts]]
source = 'content'
target = 'content'
[[module.mounts]]
source = 'static'
target = 'static'
[[module.mounts]]
source = 'layouts'
target = 'layouts'
[[module.mounts]]
source = 'data'
target = 'data'
[[module.mounts]]
source = 'assets'
target = 'assets'
[[module.mounts]]
source = 'i18n'
target = 'i18n'
[[module.mounts]]
source = 'archetypes'
target = 'archetypes'
{
"module": {
"mounts": [
{
"source": "content",
"target": "content"
},
{
"source": "static",
"target": "static"
},
{
"source": "layouts",
"target": "layouts"
},
{
"source": "data",
"target": "data"
},
{
"source": "assets",
"target": "assets"
},
{
"source": "i18n",
"target": "i18n"
},
{
"source": "archetypes",
"target": "archetypes"
}
]
}
}
- source
- (
string
) 掛載來源目錄。對於主要專案,可以是相對於專案的路徑或絕對路徑。對於其他模組,必須是相對於專案的路徑。 - target
- (
string
) 應掛載到 Hugo 虛擬檔案系統的位置。必須以 Hugo 的元件資料夾之一開頭:static
、content
、layouts
、data
、assets
、i18n
或archetypes
。例如content/blog
。 - disableWatch
- New in v0.128.0
- (
bool
) 是否在監看模式中禁用對此掛載的監看。預設為false
。 - lang
- (
string
) 語言代碼,例如 “en”。僅適用於content
掛載,以及多主機模式下的static
掛載。 - includeFiles
- (
string
或string slice
) 一個或多個 glob 模式,用於匹配要包含的檔案或目錄。如果未設定excludeFiles
,則匹配includeFiles
的檔案將是被掛載的檔案。
glob 模式與從 source
根目錄開始的檔案名稱匹配,即使在 Windows 平台上,也應使用 Unix 格式的斜線。/
匹配掛載根目錄,**
可作為超級星號匹配所有目錄,例如 /posts/**.jpg
。
搜尋不區分大小寫。
- excludeFiles
- (
string
或string slice
) 一個或多個 glob 模式,用於匹配要排除的檔案。
範例
hugo.
module:
mounts:
- excludeFiles: docs/*
source: content
target: content
- source: node_modules
target: assets
- source: assets
target: assets
[module]
[[module.mounts]]
excludeFiles = 'docs/*'
source = 'content'
target = 'content'
[[module.mounts]]
source = 'node_modules'
target = 'assets'
[[module.mounts]]
source = 'assets'
target = 'assets'
{
"module": {
"mounts": [
{
"excludeFiles": "docs/*",
"source": "content",
"target": "content"
},
{
"source": "node_modules",
"target": "assets"
},
{
"source": "assets",
"target": "assets"
}
]
}
}