mirror of
https://github.com/gohugoio/hugo.git
synced 2024-11-21 20:46:30 -05:00
parent
710142016b
commit
5f24a2c047
5 changed files with 19 additions and 13 deletions
|
@ -73,7 +73,11 @@ type Vimeo struct {
|
||||||
// YouTube holds the privacy configuration settingsrelated to the YouTube shortcode.
|
// YouTube holds the privacy configuration settingsrelated to the YouTube shortcode.
|
||||||
type YouTube struct {
|
type YouTube struct {
|
||||||
Service `mapstructure:",squash"`
|
Service `mapstructure:",squash"`
|
||||||
NoCookie bool
|
|
||||||
|
// When you turn on privacy-enhanced mode,
|
||||||
|
// YouTube won’t store information about visitors on your website
|
||||||
|
// unless they play the video.
|
||||||
|
PrivacyEnhanced bool
|
||||||
}
|
}
|
||||||
|
|
||||||
func DecodeConfig(cfg config.Provider) (pc Config, err error) {
|
func DecodeConfig(cfg config.Provider) (pc Config, err error) {
|
||||||
|
|
|
@ -44,7 +44,7 @@ disable = true
|
||||||
disable = true
|
disable = true
|
||||||
[privacy.youtube]
|
[privacy.youtube]
|
||||||
disable = true
|
disable = true
|
||||||
noCookie = true
|
privacyEnhanced = true
|
||||||
`
|
`
|
||||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
@ -61,7 +61,7 @@ noCookie = true
|
||||||
assert.True(pc.Tweet.Disable)
|
assert.True(pc.Tweet.Disable)
|
||||||
assert.True(pc.Vimeo.Disable)
|
assert.True(pc.Vimeo.Disable)
|
||||||
|
|
||||||
assert.True(pc.YouTube.NoCookie)
|
assert.True(pc.YouTube.PrivacyEnhanced)
|
||||||
assert.True(pc.YouTube.Disable)
|
assert.True(pc.YouTube.Disable)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,7 +74,7 @@ someOtherValue = "foo"
|
||||||
|
|
||||||
[Privacy]
|
[Privacy]
|
||||||
[Privacy.YouTube]
|
[Privacy.YouTube]
|
||||||
NoCOOKIE = true
|
PrivacyENhanced = true
|
||||||
`
|
`
|
||||||
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
cfg, err := config.FromConfigString(tomlConfig, "toml")
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
|
@ -82,7 +82,7 @@ NoCOOKIE = true
|
||||||
pc, err := DecodeConfig(cfg)
|
pc, err := DecodeConfig(cfg)
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(pc)
|
assert.NotNil(pc)
|
||||||
assert.True(pc.YouTube.NoCookie)
|
assert.True(pc.YouTube.PrivacyEnhanced)
|
||||||
}
|
}
|
||||||
|
|
||||||
func TestDecodeConfigDefault(t *testing.T) {
|
func TestDecodeConfigDefault(t *testing.T) {
|
||||||
|
@ -91,5 +91,5 @@ func TestDecodeConfigDefault(t *testing.T) {
|
||||||
pc, err := DecodeConfig(viper.New())
|
pc, err := DecodeConfig(viper.New())
|
||||||
assert.NoError(err)
|
assert.NoError(err)
|
||||||
assert.NotNil(pc)
|
assert.NotNil(pc)
|
||||||
assert.False(pc.YouTube.NoCookie)
|
assert.False(pc.YouTube.PrivacyEnhanced)
|
||||||
}
|
}
|
||||||
|
|
|
@ -377,13 +377,13 @@ someOtherValue = "foo"
|
||||||
|
|
||||||
[privacy]
|
[privacy]
|
||||||
[privacy.youtube]
|
[privacy.youtube]
|
||||||
noCookie = true
|
privacyEnhanced = true
|
||||||
`
|
`
|
||||||
|
|
||||||
b := newTestSitesBuilder(t)
|
b := newTestSitesBuilder(t)
|
||||||
b.WithConfigFile("toml", tomlConfig)
|
b.WithConfigFile("toml", tomlConfig)
|
||||||
b.Build(BuildCfg{SkipRender: true})
|
b.Build(BuildCfg{SkipRender: true})
|
||||||
|
|
||||||
assert.True(b.H.Sites[0].Info.PrivacyConfig.YouTube.NoCookie)
|
assert.True(b.H.Sites[0].Info.PrivacyConfig.YouTube.PrivacyEnhanced)
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,13 +287,14 @@ if (!doNotTrack) {
|
||||||
{{- end -}}`},
|
{{- end -}}`},
|
||||||
{`shortcodes/youtube.html`, `{{- $pc := .Page.Site.PrivacyConfig.YouTube -}}
|
{`shortcodes/youtube.html`, `{{- $pc := .Page.Site.PrivacyConfig.YouTube -}}
|
||||||
{{- if not $pc.Disable -}}
|
{{- if not $pc.Disable -}}
|
||||||
|
{{ $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" }}
|
||||||
{{ if .IsNamedParams }}
|
{{ if .IsNamedParams }}
|
||||||
<div {{ if .Get "class" }}class="{{ .Get "class" }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
|
<div {{ if .Get "class" }}class="{{ .Get "class" }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
|
||||||
<iframe src="//www.youtube.com/embed/{{ .Get "id" }}?{{ with .Get "autoplay" }}{{ if eq . "true" }}autoplay=1{{ end }}{{ end }}"
|
<iframe src="//{{ $ytHost }}/embed/{{ .Get "id" }}?{{ with .Get "autoplay" }}{{ if eq . "true" }}autoplay=1{{ end }}{{ end }}"
|
||||||
{{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0" title="YouTube Video"></iframe>
|
{{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0" title="YouTube Video"></iframe>
|
||||||
</div>{{ else }}
|
</div>{{ else }}
|
||||||
<div {{ if len .Params | eq 2 }}class="{{ .Get 1 }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
|
<div {{ if len .Params | eq 2 }}class="{{ .Get 1 }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
|
||||||
<iframe src="//www.youtube.com/embed/{{ .Get 0 }}" {{ if len .Params | eq 1 }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0" title="YouTube Video"></iframe>
|
<iframe src="//{{ $ytHost }}/embed/{{ .Get 0 }}" {{ if len .Params | eq 1 }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0" title="YouTube Video"></iframe>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{- end -}}`},
|
{{- end -}}`},
|
||||||
|
|
|
@ -1,12 +1,13 @@
|
||||||
{{- $pc := .Page.Site.PrivacyConfig.YouTube -}}
|
{{- $pc := .Page.Site.PrivacyConfig.YouTube -}}
|
||||||
{{- if not $pc.Disable -}}
|
{{- if not $pc.Disable -}}
|
||||||
|
{{ $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" }}
|
||||||
{{ if .IsNamedParams }}
|
{{ if .IsNamedParams }}
|
||||||
<div {{ if .Get "class" }}class="{{ .Get "class" }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
|
<div {{ if .Get "class" }}class="{{ .Get "class" }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
|
||||||
<iframe src="//www.youtube.com/embed/{{ .Get "id" }}?{{ with .Get "autoplay" }}{{ if eq . "true" }}autoplay=1{{ end }}{{ end }}"
|
<iframe src="//{{ $ytHost }}/embed/{{ .Get "id" }}?{{ with .Get "autoplay" }}{{ if eq . "true" }}autoplay=1{{ end }}{{ end }}"
|
||||||
{{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0" title="YouTube Video"></iframe>
|
{{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0" title="YouTube Video"></iframe>
|
||||||
</div>{{ else }}
|
</div>{{ else }}
|
||||||
<div {{ if len .Params | eq 2 }}class="{{ .Get 1 }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
|
<div {{ if len .Params | eq 2 }}class="{{ .Get 1 }}"{{ else }}style="position: relative; padding-bottom: 56.25%; padding-top: 30px; height: 0; overflow: hidden;"{{ end }}>
|
||||||
<iframe src="//www.youtube.com/embed/{{ .Get 0 }}" {{ if len .Params | eq 1 }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0" title="YouTube Video"></iframe>
|
<iframe src="//{{ $ytHost }}/embed/{{ .Get 0 }}" {{ if len .Params | eq 1 }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}allowfullscreen frameborder="0" title="YouTube Video"></iframe>
|
||||||
</div>
|
</div>
|
||||||
{{ end }}
|
{{ end }}
|
||||||
{{- end -}}
|
{{- end -}}
|
Loading…
Reference in a new issue