配置 Hugo 模块
模块配置:顶级配置
        hugo.
      
      
       
      
       
      
       
  module:
  noProxy: none
  noVendor: ""
  private: '*.*'
  proxy: direct
  replacements: ""
  workspace: "off"
[module]
  noProxy = 'none'
  noVendor = ''
  private = '*.*'
  proxy = 'direct'
  replacements = ''
  workspace = 'off'
{
   "module": {
      "noProxy": "none",
      "noVendor": "",
      "private": "*.*",
      "proxy": "direct",
      "replacements": "",
      "workspace": "off"
   }
}
- noVendor
- 一个可选的 Glob 模式,用于匹配模块路径,以在打包时跳过,例如 “github.com/**”
- vendorClosest
- 启用后,我们会选择距离正在使用该模块的模块最近的模块。默认行为是选择第一个。请注意,给定模块路径只能有一个依赖项,因此一旦使用它,就无法重新定义。
- proxy
- 定义用于下载远程模块的代理服务器。默认值为 direct,表示 “git clone” 等。
- noProxy
- 逗号分隔的 glob 列表,用于匹配不应使用上述配置的路径。
- private
- 逗号分隔的 glob 列表,用于匹配应视为私有的路径。
- workspace
- 要使用的工作区文件。这将启用 Go 工作区模式。请注意,这也可以通过操作系统环境设置,例如 export HUGO_MODULE_WORKSPACE=/my/hugo.work。这仅适用于 Go 1.18+。在 Hugov0.109.0中,我们将默认值更改为off,我们现在会将任何相对于工作目录的相对工作文件名解析。
- replacements
- 逗号分隔的模块路径到目录的映射列表,例如 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
- 支持的最低 Hugo 版本,例如 0.55.0
- max
- 支持的最高 Hugo 版本,例如 0.55.0
- extended
- 是否需要扩展版的 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 模块模块路径,例如 github.com/gohugoio/myShortcodes,或者模块在您的主题文件夹中存储的目录名。
- ignoreConfig
- 如果启用,将不会加载任何模块配置文件,例如 hugo.toml。请注意,这也会停止加载任何传递模块依赖项。
- ignoreImports
- 如果启用,将不会跟踪模块导入。
- disable
- 设置为 true以禁用模块,同时保留go.*文件中的任何版本信息。
- noMounts
- 不在此导入中挂载任何文件夹。
- noVendor
- 永远不要将此导入作为依赖项打包(仅在主项目中允许)。
模块配置:mounts
默认的 mount
        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
- mount 的源文件夹。对于主项目,它可以是项目相对路径、绝对路径,甚至一个符号链接。对于其他模块,它必须是项目相对路径。
- target
- 它应该安装到 Hugo 的虚拟文件系统中的位置。它必须以 Hugo 的组件文件夹之一开头:static、content、layouts、data、assets、i18n或archetypes。例如content/blog。
- lang
- 语言代码,例如 “en”。仅适用于 contentmount 和多主机模式下的staticmount。
- includeFiles(字符串或切片)
- 一个或多个匹配文件或目录的 glob 模式。如果未设置 excludeFiles,则匹配includeFiles的文件将被挂载。
glob 模式匹配从 source 根开始的文件名,它们应该使用 Unix 风格的斜杠,即使在 Windows 上也是如此。/ 匹配 mount 根目录,** 可以用作超级星号,递归匹配所有目录,例如 /posts/**.jpg。
搜索不区分大小写。
- excludeFiles(字符串或切片)
- 一个或多个匹配要排除的文件的 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"
         }
      ]
   }
}