Move the privacy config into a parent

See #4751
This commit is contained in:
Bjørn Erik Pedersen 2018-05-22 14:00:36 +02:00
parent 568b4335c2
commit 353148c2bc
10 changed files with 23 additions and 19 deletions

View file

@ -22,11 +22,19 @@ import (
"strings" "strings"
"github.com/gohugoio/hugo/config" "github.com/gohugoio/hugo/config"
"github.com/gohugoio/hugo/config/privacy"
"github.com/gohugoio/hugo/helpers" "github.com/gohugoio/hugo/helpers"
"github.com/spf13/afero" "github.com/spf13/afero"
"github.com/spf13/viper" "github.com/spf13/viper"
) )
// SiteConfig represents the config in .Site.Config.
type SiteConfig struct {
// This contains all privacy related settings that can be used to
// make the YouTube template etc. GDPR compliant.
Privacy privacy.Config
}
// ConfigSourceDescriptor describes where to find the config (e.g. config.toml etc.). // ConfigSourceDescriptor describes where to find the config (e.g. config.toml etc.).
type ConfigSourceDescriptor struct { type ConfigSourceDescriptor struct {
Fs afero.Fs Fs afero.Fs

View file

@ -384,6 +384,6 @@ privacyEnhanced = true
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.PrivacyEnhanced) assert.True(b.H.Sites[0].Info.Config.Privacy.YouTube.PrivacyEnhanced)
} }

View file

@ -388,11 +388,7 @@ type SiteInfo struct {
preserveTaxonomyNames bool preserveTaxonomyNames bool
Data *map[string]interface{} Data *map[string]interface{}
// This contains all privacy related settings that can be used to Config SiteConfig
// make the YouTube template etc.GDPR compliant.
// It is mostly in use by Hugo's built-in, but is also available
// for end users with {{ .Site.PrivacyConfig.YouTube.NoCookie }} etc.
PrivacyConfig privacy.Config
owner *HugoSites owner *HugoSites
s *Site s *Site
@ -1151,7 +1147,7 @@ func (s *Site) initializeSiteInfo() error {
Data: &s.Data, Data: &s.Data,
owner: s.owner, owner: s.owner,
s: s, s: s,
PrivacyConfig: privacyConfig, Config: SiteConfig{Privacy: privacyConfig},
} }
rssOutputFormat, found := s.outputFormats[KindHome].GetByName(output.RSSFormat.Name) rssOutputFormat, found := s.outputFormats[KindHome].GetByName(output.RSSFormat.Name)

View file

@ -76,7 +76,7 @@ var EmbeddedTemplates = [][2]string{
{{ end }} {{ end }}
</sitemapindex> </sitemapindex>
`}, `},
{`disqus.html`, `{{- $pc := .Page.Site.PrivacyConfig.Disqus -}} {`disqus.html`, `{{- $pc := .Page.Site.Config.Privacy.Disqus -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{ if .Site.DisqusShortname }}<div id="disqus_thread"></div> {{ if .Site.DisqusShortname }}<div id="disqus_thread"></div>
<script> <script>
@ -296,21 +296,21 @@ M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.5
<!-- image -->`}, <!-- image -->`},
{`shortcodes/gist.html`, `<script src="//gist.github.com/{{ index .Params 0 }}/{{ index .Params 1 }}.js{{if len .Params | eq 3 }}?file={{ index .Params 2 }}{{end}}"></script>`}, {`shortcodes/gist.html`, `<script src="//gist.github.com/{{ index .Params 0 }}/{{ index .Params 1 }}.js{{if len .Params | eq 3 }}?file={{ index .Params 2 }}{{end}}"></script>`},
{`shortcodes/highlight.html`, `{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}`}, {`shortcodes/highlight.html`, `{{ if len .Params | eq 2 }}{{ highlight (trim .Inner "\n\r") (.Get 0) (.Get 1) }}{{ else }}{{ highlight (trim .Inner "\n\r") (.Get 0) "" }}{{ end }}`},
{`shortcodes/instagram.html`, `{{- $pc := .Page.Site.PrivacyConfig.Instagram -}} {`shortcodes/instagram.html`, `{{- $pc := .Page.Site.Config.Privacy.Instagram -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{ if len .Params | eq 2 }}{{ if eq (.Get 1) "hidecaption" }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=1" }}{{ .html | safeHTML }}{{ end }}{{ end }}{{ else }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=0" }}{{ .html | safeHTML }}{{ end }}{{ end }} {{ if len .Params | eq 2 }}{{ if eq (.Get 1) "hidecaption" }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=1" }}{{ .html | safeHTML }}{{ end }}{{ end }}{{ else }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=0" }}{{ .html | safeHTML }}{{ end }}{{ end }}
{{- end -}}`}, {{- end -}}`},
{`shortcodes/ref.html`, `{{ if len .Params | eq 2 }}{{ ref .Page (.Get 0) (.Get 1) }}{{ else }}{{ ref .Page (.Get 0) }}{{ end }}`}, {`shortcodes/ref.html`, `{{ if len .Params | eq 2 }}{{ ref .Page (.Get 0) (.Get 1) }}{{ else }}{{ ref .Page (.Get 0) }}{{ end }}`},
{`shortcodes/relref.html`, `{{ if len .Params | eq 2 }}{{ relref .Page (.Get 0) (.Get 1) }}{{ else }}{{ relref .Page (.Get 0) }}{{ end }}`}, {`shortcodes/relref.html`, `{{ if len .Params | eq 2 }}{{ relref .Page (.Get 0) (.Get 1) }}{{ else }}{{ relref .Page (.Get 0) }}{{ end }}`},
{`shortcodes/speakerdeck.html`, `{{- $pc := .Page.Site.PrivacyConfig.SpeakerDeck -}} {`shortcodes/speakerdeck.html`, `{{- $pc := .Page.Site.Config.Privacy.SpeakerDeck -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
<script async class='speakerdeck-embed' data-id='{{ index .Params 0 }}' data-ratio='1.33333333333333' src='//speakerdeck.com/assets/embed.js'></script> <script async class='speakerdeck-embed' data-id='{{ index .Params 0 }}' data-ratio='1.33333333333333' src='//speakerdeck.com/assets/embed.js'></script>
{{- end -}}`}, {{- end -}}`},
{`shortcodes/tweet.html`, `{{- $pc := .Page.Site.PrivacyConfig.Tweet -}} {`shortcodes/tweet.html`, `{{- $pc := .Page.Site.Config.Privacy.Tweet -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }} {{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}
{{- end -}}`}, {{- end -}}`},
{`shortcodes/vimeo.html`, `{{- $pc := .Page.Site.PrivacyConfig.Vimeo -}} {`shortcodes/vimeo.html`, `{{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{ 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 }}> {{ 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 }}>
<iframe src="//player.vimeo.com/video/{{ .Get "id" }}" {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <iframe src="//player.vimeo.com/video/{{ .Get "id" }}" {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>
@ -320,7 +320,7 @@ M66.52,7.74c-0.78-2.93-2.49-5.41-5.42-6.19C55.79,.13,34,0,34,0S12.21,.13,6.9,1.5
</div> </div>
{{ end }} {{ end }}
{{- end -}}`}, {{- end -}}`},
{`shortcodes/youtube.html`, `{{- $pc := .Page.Site.PrivacyConfig.YouTube -}} {`shortcodes/youtube.html`, `{{- $pc := .Page.Site.Config.Privacy.YouTube -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} {{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}}
{{- if $pc.Simple -}} {{- if $pc.Simple -}}

View file

@ -1,4 +1,4 @@
{{- $pc := .Page.Site.PrivacyConfig.Disqus -}} {{- $pc := .Page.Site.Config.Privacy.Disqus -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{ if .Site.DisqusShortname }}<div id="disqus_thread"></div> {{ if .Site.DisqusShortname }}<div id="disqus_thread"></div>
<script> <script>

View file

@ -1,4 +1,4 @@
{{- $pc := .Page.Site.PrivacyConfig.Instagram -}} {{- $pc := .Page.Site.Config.Privacy.Instagram -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{ if len .Params | eq 2 }}{{ if eq (.Get 1) "hidecaption" }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=1" }}{{ .html | safeHTML }}{{ end }}{{ end }}{{ else }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=0" }}{{ .html | safeHTML }}{{ end }}{{ end }} {{ if len .Params | eq 2 }}{{ if eq (.Get 1) "hidecaption" }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=1" }}{{ .html | safeHTML }}{{ end }}{{ end }}{{ else }}{{ with getJSON "https://api.instagram.com/oembed/?url=https://instagram.com/p/" (index .Params 0) "/&hidecaption=0" }}{{ .html | safeHTML }}{{ end }}{{ end }}
{{- end -}} {{- end -}}

View file

@ -1,4 +1,4 @@
{{- $pc := .Page.Site.PrivacyConfig.SpeakerDeck -}} {{- $pc := .Page.Site.Config.Privacy.SpeakerDeck -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
<script async class='speakerdeck-embed' data-id='{{ index .Params 0 }}' data-ratio='1.33333333333333' src='//speakerdeck.com/assets/embed.js'></script> <script async class='speakerdeck-embed' data-id='{{ index .Params 0 }}' data-ratio='1.33333333333333' src='//speakerdeck.com/assets/embed.js'></script>
{{- end -}} {{- end -}}

View file

@ -1,4 +1,4 @@
{{- $pc := .Page.Site.PrivacyConfig.Tweet -}} {{- $pc := .Page.Site.Config.Privacy.Tweet -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }} {{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}
{{- end -}} {{- end -}}

View file

@ -1,4 +1,4 @@
{{- $pc := .Page.Site.PrivacyConfig.Vimeo -}} {{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{ 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 }}> {{ 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 }}>
<iframe src="//player.vimeo.com/video/{{ .Get "id" }}" {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe> <iframe src="//player.vimeo.com/video/{{ .Get "id" }}" {{ if not (.Get "class") }}style="position: absolute; top: 0; left: 0; width: 100%; height: 100%;" {{ end }}webkitallowfullscreen mozallowfullscreen allowfullscreen></iframe>

View file

@ -1,4 +1,4 @@
{{- $pc := .Page.Site.PrivacyConfig.YouTube -}} {{- $pc := .Page.Site.Config.Privacy.YouTube -}}
{{- if not $pc.Disable -}} {{- if not $pc.Disable -}}
{{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} {{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}}
{{- if $pc.Simple -}} {{- if $pc.Simple -}}