HUGO
Menu
GitHub 87548 stars Mastodon

配置部署

配置部署到 Amazon S3、Azure Blob Storage 或 Google Cloud Storage。

此配置仅在运行 hugo deploy 时相关。详见 详情

顶级选项

这些设置控制部署过程的整体行为。这是默认配置:

deployment:
  confirm: false
  dryRun: false
  force: false
  invalidateCDN: true
  matchers: null
  maxDeletes: 256
  order: null
  target: ''
  targets: null
  workers: 10
[deployment]
  confirm = false
  dryRun = false
  force = false
  invalidateCDN = true
  maxDeletes = 256
  target = ''
  workers = 10
{
   "deployment": {
      "confirm": false,
      "dryRun": false,
      "force": false,
      "invalidateCDN": true,
      "matchers": null,
      "maxDeletes": 256,
      "order": null,
      "target": "",
      "targets": null,
      "workers": 10
   }
}
confirm
(bool) 是否在部署前提示确认。默认值是 false
dryRun
(bool) 是否模拟部署而不进行任何远程更改。默认值是 false
force
(bool) 是否重新上传所有文件。默认值是 false
invalidateCDN
(bool) 是否使部署目标中列出的 CDN 缓存失效。默认值是 true
maxDeletes
(int) 要删除的最大文件数,或 -1 禁用。默认值是 256
matchers
([]*Matcher) 匹配器 切片。
order
([]string) 确定上传优先级的有序 正则表达式 切片(从左到右)。不匹配任何表达式的文件以任意顺序最后上传。
target
(string) 目标部署 name。默认为第一个目标。
targets
([]*Target) 目标 切片。
workers
(int) 上传文件时使用的并发工作线程数。默认值是 10

目标

目标表示部署目标,如 “staging” 或 “production”。

cloudFrontDistributionID
(string) CloudFront 分发 ID,适用于使用 Amazon Web Services CloudFront CDN 的情况。Hugo 将在部署此目标时使 CDN 缓存失效。
exclude
(string) 匹配部署到此目标时要排除的文件的 glob 模式。未通过包含/排除过滤器的本地文件不会上传,未通过这些过滤器的远程文件不会删除。
googleCloudCDNOrigin
(string) 部署此目标时要失效的 Google Cloud 项目和 CDN 源,指定为 <project>/<origin>
include
(string) 匹配部署到此目标时要包含的文件的 glob 模式。未通过包含/排除过滤器的本地文件不会上传,未通过这些过滤器的远程文件不会删除。
name
(string) 此目标的任意名称。
stripIndexHTML
(bool) 是否将名为 <dir>/index.html 的文件映射到远程的 <dir>(根 index.html 除外)。这对于键值云存储(如 Amazon S3、Google Cloud Storage、Azure Blob Storage)很有用,可使规范 URL 与对象键对齐。默认值是 false
url
(string) 部署的 目标 URL

匹配器

匹配器表示要应用于路径与指定模式匹配的文件的配置。

cacheControl
(string) 提供 blob 时使用的缓存属性。详见 详情
contentEncoding
(string) 用于 blob 内容的编码(如果有)。详见 详情
contentType
(string) 正在写入的 blob 的媒体类型。详见 详情
force
(bool) 是否应重新上传匹配的文件。当其他路由确定的元数据(如 contentType)已更改时很有用。默认值是 false
gzip
(bool) 文件是否应在上传前进行 gzip 压缩。如果是,ContentEncoding 字段将自动设置为 gzip。默认值是 false
pattern
(string) 用于匹配路径的 正则表达式。路径在匹配前转换为使用正斜杠 (/)。

目标 URL

服务 URL 示例
Amazon Simple Storage Service (S3) s3://my-bucket?region=us-west-1
Azure Blob Storage azblob://my-container
Google Cloud Storage (GCS) gs://my-bucket

使用 Google Cloud Storage,您可以定位到子目录:

gs://my-bucket?prefix=a/subdirectory

您还可以部署到与 Amazon S3 兼容的存储服务器,如:

例如,MinIO 部署目标的 url 可能类似于:

s3://my-bucket?endpoint=https://my.minio.instance&awssdk=v2&use_path_style=true&disable_https=false

示例

deployment:
  matchers:
  - cacheControl: max-age=31536000, no-transform, public
    gzip: true
    pattern: '^.+\.(js|css|svg|ttf)$'
  - cacheControl: max-age=31536000, no-transform, public
    gzip: false
    pattern: '^.+\.(png|jpg)$'
  - contentType: application/xml
    gzip: true
    pattern: '^sitemap\.xml$'
  - gzip: true
    pattern: '^.+\.(html|xml|json)$'
  order:
  - .jpg$
  - .gif$
  targets:
  - cloudFrontDistributionID: E1234567890ABCDEF0
    exclude: '**.{heic,psd}'
    name: production
    url: s3://my_production_bucket?region=us-west-1
  - exclude: '**.{heic,psd}'
    name: staging
    url: s3://my_staging_bucket?region=us-west-1
[deployment]
  order = ['.jpg$', '.gif$']
  [[deployment.matchers]]
    cacheControl = 'max-age=31536000, no-transform, public'
    gzip = true
    pattern = '^.+\.(js|css|svg|ttf)$'
  [[deployment.matchers]]
    cacheControl = 'max-age=31536000, no-transform, public'
    gzip = false
    pattern = '^.+\.(png|jpg)$'
  [[deployment.matchers]]
    contentType = 'application/xml'
    gzip = true
    pattern = '^sitemap\.xml$'
  [[deployment.matchers]]
    gzip = true
    pattern = '^.+\.(html|xml|json)$'
  [[deployment.targets]]
    cloudFrontDistributionID = 'E1234567890ABCDEF0'
    exclude = '**.{heic,psd}'
    name = 'production'
    url = 's3://my_production_bucket?region=us-west-1'
  [[deployment.targets]]
    exclude = '**.{heic,psd}'
    name = 'staging'
    url = 's3://my_staging_bucket?region=us-west-1'
{
   "deployment": {
      "matchers": [
         {
            "cacheControl": "max-age=31536000, no-transform, public",
            "gzip": true,
            "pattern": "^.+\\.(js|css|svg|ttf)$"
         },
         {
            "cacheControl": "max-age=31536000, no-transform, public",
            "gzip": false,
            "pattern": "^.+\\.(png|jpg)$"
         },
         {
            "contentType": "application/xml",
            "gzip": true,
            "pattern": "^sitemap\\.xml$"
         },
         {
            "gzip": true,
            "pattern": "^.+\\.(html|xml|json)$"
         }
      ],
      "order": [
         ".jpg$",
         ".gif$"
      ],
      "targets": [
         {
            "cloudFrontDistributionID": "E1234567890ABCDEF0",
            "exclude": "**.{heic,psd}",
            "name": "production",
            "url": "s3://my_production_bucket?region=us-west-1"
         },
         {
            "exclude": "**.{heic,psd}",
            "name": "staging",
            "url": "s3://my_staging_bucket?region=us-west-1"
         }
      ]
   }
}

Last updated: January 1, 0001
Improve this page