mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
Drop dashes in http header matcher attributes; other changes from code review
This commit is contained in:
parent
1384d77a04
commit
b0f536fb27
4 changed files with 70 additions and 50 deletions
|
@ -68,7 +68,7 @@ func newDeployCmd() *deployCmd {
|
||||||
cc.cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target")
|
cc.cmd.Flags().Bool("confirm", false, "ask for confirmation before making changes to the target")
|
||||||
cc.cmd.Flags().Bool("dryRun", false, "dry run")
|
cc.cmd.Flags().Bool("dryRun", false, "dry run")
|
||||||
cc.cmd.Flags().Bool("force", false, "force upload of all files")
|
cc.cmd.Flags().Bool("force", false, "force upload of all files")
|
||||||
cc.cmd.Flags().Bool("invalidateCDN", true, "invalidate the CDN cache via the CloudFrontDistributionID listed in the deployment target")
|
cc.cmd.Flags().Bool("invalidateCDN", true, "invalidate the CDN cache via the cloudFrontDistributionID listed in the deployment target")
|
||||||
cc.cmd.Flags().Int("maxDeletes", 256, "maximum # of files to delete, or -1 to disable")
|
cc.cmd.Flags().Int("maxDeletes", 256, "maximum # of files to delete, or -1 to disable")
|
||||||
|
|
||||||
return cc
|
return cc
|
||||||
|
|
|
@ -48,15 +48,15 @@ type matcher struct {
|
||||||
|
|
||||||
// CacheControl specifies caching attributes to use when serving the blob.
|
// CacheControl specifies caching attributes to use when serving the blob.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Cache-Control
|
||||||
CacheControl string `mapstructure:"Cache-Control"`
|
CacheControl string
|
||||||
|
|
||||||
// ContentEncoding specifies the encoding used for the blob's content, if any.
|
// ContentEncoding specifies the encoding used for the blob's content, if any.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Encoding
|
||||||
ContentEncoding string `mapstructure:"Content-Encoding"`
|
ContentEncoding string
|
||||||
|
|
||||||
// ContentType specifies the MIME type of the blob being written.
|
// ContentType specifies the MIME type of the blob being written.
|
||||||
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
|
// https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Content-Type
|
||||||
ContentType string `mapstructure:"Content-Type"`
|
ContentType string
|
||||||
|
|
||||||
// Gzip determines whether the file should be gzipped before upload.
|
// Gzip determines whether the file should be gzipped before upload.
|
||||||
// If so, the ContentEncoding field will automatically be set to "gzip".
|
// If so, the ContentEncoding field will automatically be set to "gzip".
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
package deploy
|
package deploy
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
"github.com/gohugoio/hugo/config"
|
"github.com/gohugoio/hugo/config"
|
||||||
|
@ -32,29 +33,48 @@ someOtherValue = "foo"
|
||||||
|
|
||||||
order = ["o1", "o2"]
|
order = ["o1", "o2"]
|
||||||
|
|
||||||
|
# All lowercase.
|
||||||
[[deployment.targets]]
|
[[deployment.targets]]
|
||||||
Name = "name1"
|
name = "name0"
|
||||||
URL = "url1"
|
url = "url0"
|
||||||
CloudFrontDistributionID = "cdn1"
|
cloudfrontdistributionid = "cdn0"
|
||||||
|
|
||||||
|
# All uppercase.
|
||||||
|
[[deployment.targets]]
|
||||||
|
NAME = "name1"
|
||||||
|
URL = "url1"
|
||||||
|
CLOUDFRONTDISTRIBUTIONID = "cdn1"
|
||||||
|
|
||||||
|
# Camelcase.
|
||||||
[[deployment.targets]]
|
[[deployment.targets]]
|
||||||
name = "name2"
|
name = "name2"
|
||||||
url = "url2"
|
url = "url2"
|
||||||
cloudfrontdistributionid = "cdn2"
|
cloudFrontDistributionID = "cdn2"
|
||||||
|
|
||||||
|
# All lowercase.
|
||||||
[[deployment.matchers]]
|
[[deployment.matchers]]
|
||||||
Pattern = "^pattern1$"
|
pattern = "^pattern0$"
|
||||||
Cache-Control = "cachecontrol1"
|
cachecontrol = "cachecontrol0"
|
||||||
Content-Encoding = "contentencoding1"
|
contentencoding = "contentencoding0"
|
||||||
Content-Type = "contenttype1"
|
contenttype = "contenttype0"
|
||||||
Gzip = true
|
|
||||||
Force = true
|
|
||||||
|
|
||||||
|
# All uppercase.
|
||||||
|
[[deployment.matchers]]
|
||||||
|
PATTERN = "^pattern1$"
|
||||||
|
CACHECONTROL = "cachecontrol1"
|
||||||
|
CONTENTENCODING = "contentencoding1"
|
||||||
|
CONTENTTYPE = "contenttype1"
|
||||||
|
GZIP = true
|
||||||
|
FORCE = true
|
||||||
|
|
||||||
|
# Camelcase.
|
||||||
[[deployment.matchers]]
|
[[deployment.matchers]]
|
||||||
pattern = "^pattern2$"
|
pattern = "^pattern2$"
|
||||||
cache-control = "cachecontrol2"
|
cacheControl = "cachecontrol2"
|
||||||
content-encoding = "contentencoding2"
|
contentEncoding = "contentencoding2"
|
||||||
content-type = "contenttype2"
|
contentType = "contenttype2"
|
||||||
|
gzip = true
|
||||||
|
force = true
|
||||||
`
|
`
|
||||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
@ -62,34 +82,33 @@ content-type = "contenttype2"
|
||||||
dcfg, err := decodeConfig(cfg)
|
dcfg, err := decodeConfig(cfg)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
|
||||||
|
// Order.
|
||||||
assert.Equal(2, len(dcfg.Order))
|
assert.Equal(2, len(dcfg.Order))
|
||||||
assert.Equal("o1", dcfg.Order[0])
|
assert.Equal("o1", dcfg.Order[0])
|
||||||
assert.Equal("o2", dcfg.Order[1])
|
assert.Equal("o2", dcfg.Order[1])
|
||||||
assert.Equal(2, len(dcfg.ordering))
|
assert.Equal(2, len(dcfg.ordering))
|
||||||
|
|
||||||
assert.Equal(2, len(dcfg.Targets))
|
// Targets.
|
||||||
assert.Equal("name1", dcfg.Targets[0].Name)
|
assert.Equal(3, len(dcfg.Targets))
|
||||||
assert.Equal("url1", dcfg.Targets[0].URL)
|
for i := 0; i < 3; i++ {
|
||||||
assert.Equal("cdn1", dcfg.Targets[0].CloudFrontDistributionID)
|
tgt := dcfg.Targets[i]
|
||||||
assert.Equal("name2", dcfg.Targets[1].Name)
|
assert.Equal(fmt.Sprintf("name%d", i), tgt.Name)
|
||||||
assert.Equal("url2", dcfg.Targets[1].URL)
|
assert.Equal(fmt.Sprintf("url%d", i), tgt.URL)
|
||||||
assert.Equal("cdn2", dcfg.Targets[1].CloudFrontDistributionID)
|
assert.Equal(fmt.Sprintf("cdn%d", i), tgt.CloudFrontDistributionID)
|
||||||
|
}
|
||||||
|
|
||||||
assert.Equal(2, len(dcfg.Matchers))
|
// Matchers.
|
||||||
assert.Equal("^pattern1$", dcfg.Matchers[0].Pattern)
|
assert.Equal(3, len(dcfg.Matchers))
|
||||||
assert.NotNil(dcfg.Matchers[0].re)
|
for i := 0; i < 3; i++ {
|
||||||
assert.Equal("cachecontrol1", dcfg.Matchers[0].CacheControl)
|
m := dcfg.Matchers[i]
|
||||||
assert.Equal("contentencoding1", dcfg.Matchers[0].ContentEncoding)
|
assert.Equal(fmt.Sprintf("^pattern%d$", i), m.Pattern)
|
||||||
assert.Equal("contenttype1", dcfg.Matchers[0].ContentType)
|
assert.NotNil(m.re)
|
||||||
assert.True(dcfg.Matchers[0].Gzip)
|
assert.Equal(fmt.Sprintf("cachecontrol%d", i), m.CacheControl)
|
||||||
assert.True(dcfg.Matchers[0].Force)
|
assert.Equal(fmt.Sprintf("contentencoding%d", i), m.ContentEncoding)
|
||||||
assert.Equal("^pattern2$", dcfg.Matchers[1].Pattern)
|
assert.Equal(fmt.Sprintf("contenttype%d", i), m.ContentType)
|
||||||
assert.NotNil(dcfg.Matchers[1].re)
|
assert.Equal(i != 0, m.Gzip)
|
||||||
assert.Equal("cachecontrol2", dcfg.Matchers[1].CacheControl)
|
assert.Equal(i != 0, m.Force)
|
||||||
assert.Equal("contentencoding2", dcfg.Matchers[1].ContentEncoding)
|
}
|
||||||
assert.Equal("contenttype2", dcfg.Matchers[1].ContentType)
|
|
||||||
assert.False(dcfg.Matchers[1].Gzip)
|
|
||||||
assert.False(dcfg.Matchers[1].Force)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestInvalidOrderingPattern(t *testing.T) {
|
func TestInvalidOrderingPattern(t *testing.T) {
|
||||||
|
|
|
@ -58,12 +58,12 @@ a detailed example:
|
||||||
# By default, files are uploaded in an arbitrary order.
|
# By default, files are uploaded in an arbitrary order.
|
||||||
# Files that match the regular expressions in the "Order" list
|
# Files that match the regular expressions in the "Order" list
|
||||||
# will be uploaded first, in the listed order.
|
# will be uploaded first, in the listed order.
|
||||||
Order = [".jpg$", ".gif$"]
|
order = [".jpg$", ".gif$"]
|
||||||
|
|
||||||
|
|
||||||
[[deployment.targets]]
|
[[deployment.targets]]
|
||||||
# An arbitrary name for this target.
|
# An arbitrary name for this target.
|
||||||
Name = "mydeployment"
|
name = "mydeployment"
|
||||||
# The Go Cloud Development Kit URL to deploy to. Examples:
|
# The Go Cloud Development Kit URL to deploy to. Examples:
|
||||||
# URL = "gs://<Bucket Name>" # For GCS; see https://gocloud.dev/howto/blob/open-bucket/#gcs.
|
# URL = "gs://<Bucket Name>" # For GCS; see https://gocloud.dev/howto/blob/open-bucket/#gcs.
|
||||||
# URL = "s3://<Bucket Name>?region=<AWS region>" # For S3; see https://gocloud.dev/howto/blob/open-bucket/#s3.
|
# URL = "s3://<Bucket Name>?region=<AWS region>" # For S3; see https://gocloud.dev/howto/blob/open-bucket/#s3.
|
||||||
|
@ -71,7 +71,7 @@ Name = "mydeployment"
|
||||||
# You can use a "prefix=" query parameter to target a subfolder of the bucket:
|
# You can use a "prefix=" query parameter to target a subfolder of the bucket:
|
||||||
# URL = "gs://<Bucket Name>?prefix=a/subfolder/"
|
# URL = "gs://<Bucket Name>?prefix=a/subfolder/"
|
||||||
# If you are using a CloudFront CDN, deploy will invalidate the cache as needed.
|
# If you are using a CloudFront CDN, deploy will invalidate the cache as needed.
|
||||||
CloudFrontDistributionID = <ID>
|
cloudFrontDistributionID = <ID>
|
||||||
|
|
||||||
|
|
||||||
# ... add more [[deployment.targets]] sections ...
|
# ... add more [[deployment.targets]] sections ...
|
||||||
|
@ -82,17 +82,17 @@ CloudFrontDistributionID = <ID>
|
||||||
|
|
||||||
[[deployment.matchers]]
|
[[deployment.matchers]]
|
||||||
# Cache static assets for 20 years.
|
# Cache static assets for 20 years.
|
||||||
Pattern = "^.+\\.(js|css|svg|ttf)$"
|
pattern = "^.+\\.(js|css|svg|ttf)$"
|
||||||
Cache-Control = "max-age=630720000, no-transform, public"
|
cacheControl = "max-age=630720000, no-transform, public"
|
||||||
gzip = true
|
gzip = true
|
||||||
|
|
||||||
[[deployment.matchers]]
|
[[deployment.matchers]]
|
||||||
Pattern = "^.+\\.(png|jpg)$"
|
pattern = "^.+\\.(png|jpg)$"
|
||||||
Cache-Control = "max-age=630720000, no-transform, public"
|
cacheControl = "max-age=630720000, no-transform, public"
|
||||||
gzip = false
|
gzip = false
|
||||||
|
|
||||||
[[deployment.matchers]]
|
[[deployment.matchers]]
|
||||||
Pattern = "^.+\\.(html|xml|json)$"
|
pattern = "^.+\\.(html|xml|json)$"
|
||||||
gzip = true
|
gzip = true
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -100,11 +100,12 @@ gzip = true
|
||||||
|
|
||||||
To deploy to a target:
|
To deploy to a target:
|
||||||
```
|
```
|
||||||
hugo deploy --target=<target>
|
hugo deploy --target=<target name>
|
||||||
```
|
```
|
||||||
|
|
||||||
Hugo will identify any local changes that need to be uploaded, and ask for
|
Hugo will identify and apply any local changes that need to be reflected to the
|
||||||
confirmation before doing anything.
|
remote target. You can use `--dryRun` to see the changes without applying them,
|
||||||
|
or `--confirm` to be prompted before making changes.
|
||||||
|
|
||||||
See `hugo help deploy` for more command-line options.
|
See `hugo help deploy` for more command-line options.
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue