配置部署
配置部署到 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"
}
]
}
}