配置 Hugo 模块
模块配置:顶级
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 模式,匹配在进行依赖包管理时要跳过的模块路径,例如 “github.com/**” - private
- (
string
) 逗号分隔的 glob 列表,匹配应被视为私有的路径。 - proxy
- (
string
) 定义用于下载远程模块的代理服务器。默认为direct
,表示使用 “git clone” 等命令。 - vendorClosest
- (
bool
) 启用后,我们将选择最接近使用它的模块的依赖包版本。默认行为是选择第一个。请注意,给定模块路径仍然只能有一个依赖项,因此一旦它被使用,就不能重新定义。默认为false
。 - workspace
- (
string
) 要使用的 workspace 文件。这将启用 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 的扩展版本。
模块配置:导入
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
- 从不为该导入创建依赖包(仅允许在主项目中)。
模块配置:挂载
默认挂载点
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"
}
]
}
}