From 353148c2bc2cdb9f2eb8ee967ba756ce09323801 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B8rn=20Erik=20Pedersen?= Date: Tue, 22 May 2018 14:00:36 +0200 Subject: [PATCH] Move the privacy config into a parent See #4751 --- hugolib/config.go | 8 ++++++++ hugolib/config_test.go | 2 +- hugolib/site.go | 8 ++------ tpl/tplimpl/embedded/templates.autogen.go | 12 ++++++------ tpl/tplimpl/embedded/templates/disqus.html | 2 +- .../embedded/templates/shortcodes/instagram.html | 2 +- .../embedded/templates/shortcodes/speakerdeck.html | 2 +- tpl/tplimpl/embedded/templates/shortcodes/tweet.html | 2 +- tpl/tplimpl/embedded/templates/shortcodes/vimeo.html | 2 +- .../embedded/templates/shortcodes/youtube.html | 2 +- 10 files changed, 23 insertions(+), 19 deletions(-) diff --git a/hugolib/config.go b/hugolib/config.go index cc808597c..b9cfd92d6 100644 --- a/hugolib/config.go +++ b/hugolib/config.go @@ -22,11 +22,19 @@ import ( "strings" "github.com/gohugoio/hugo/config" + "github.com/gohugoio/hugo/config/privacy" "github.com/gohugoio/hugo/helpers" "github.com/spf13/afero" "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.). type ConfigSourceDescriptor struct { Fs afero.Fs diff --git a/hugolib/config_test.go b/hugolib/config_test.go index f6306dec1..aec673369 100644 --- a/hugolib/config_test.go +++ b/hugolib/config_test.go @@ -384,6 +384,6 @@ privacyEnhanced = true b.WithConfigFile("toml", tomlConfig) 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) } diff --git a/hugolib/site.go b/hugolib/site.go index 0ee0db4a7..b6ba636d4 100644 --- a/hugolib/site.go +++ b/hugolib/site.go @@ -388,11 +388,7 @@ type SiteInfo struct { preserveTaxonomyNames bool Data *map[string]interface{} - // This contains all privacy related settings that can be used to - // 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 + Config SiteConfig owner *HugoSites s *Site @@ -1151,7 +1147,7 @@ func (s *Site) initializeSiteInfo() error { Data: &s.Data, owner: s.owner, s: s, - PrivacyConfig: privacyConfig, + Config: SiteConfig{Privacy: privacyConfig}, } rssOutputFormat, found := s.outputFormats[KindHome].GetByName(output.RSSFormat.Name) diff --git a/tpl/tplimpl/embedded/templates.autogen.go b/tpl/tplimpl/embedded/templates.autogen.go index ff65fe6a8..bd33e77b5 100644 --- a/tpl/tplimpl/embedded/templates.autogen.go +++ b/tpl/tplimpl/embedded/templates.autogen.go @@ -76,7 +76,7 @@ var EmbeddedTemplates = [][2]string{ {{ end }} `}, - {`disqus.html`, `{{- $pc := .Page.Site.PrivacyConfig.Disqus -}} + {`disqus.html`, `{{- $pc := .Page.Site.Config.Privacy.Disqus -}} {{- if not $pc.Disable -}} {{ if .Site.DisqusShortname }}
`}, {`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 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 -}}`}, {`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/speakerdeck.html`, `{{- $pc := .Page.Site.PrivacyConfig.SpeakerDeck -}} + {`shortcodes/speakerdeck.html`, `{{- $pc := .Page.Site.Config.Privacy.SpeakerDeck -}} {{- if not $pc.Disable -}} {{- end -}}`}, - {`shortcodes/tweet.html`, `{{- $pc := .Page.Site.PrivacyConfig.Tweet -}} + {`shortcodes/tweet.html`, `{{- $pc := .Page.Site.Config.Privacy.Tweet -}} {{- if not $pc.Disable -}} {{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }} {{- end -}}`}, - {`shortcodes/vimeo.html`, `{{- $pc := .Page.Site.PrivacyConfig.Vimeo -}} + {`shortcodes/vimeo.html`, `{{- $pc := .Page.Site.Config.Privacy.Vimeo -}} {{- if not $pc.Disable -}} {{ if .IsNamedParams }}
@@ -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
{{ end }} {{- end -}}`}, - {`shortcodes/youtube.html`, `{{- $pc := .Page.Site.PrivacyConfig.YouTube -}} + {`shortcodes/youtube.html`, `{{- $pc := .Page.Site.Config.Privacy.YouTube -}} {{- if not $pc.Disable -}} {{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} {{- if $pc.Simple -}} diff --git a/tpl/tplimpl/embedded/templates/disqus.html b/tpl/tplimpl/embedded/templates/disqus.html index 3f44369a7..aebcd1447 100755 --- a/tpl/tplimpl/embedded/templates/disqus.html +++ b/tpl/tplimpl/embedded/templates/disqus.html @@ -1,4 +1,4 @@ -{{- $pc := .Page.Site.PrivacyConfig.Disqus -}} +{{- $pc := .Page.Site.Config.Privacy.Disqus -}} {{- if not $pc.Disable -}} {{ if .Site.DisqusShortname }}
{{- end -}} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/tweet.html b/tpl/tplimpl/embedded/templates/shortcodes/tweet.html index ef2dd07a1..09adaf7e9 100755 --- a/tpl/tplimpl/embedded/templates/shortcodes/tweet.html +++ b/tpl/tplimpl/embedded/templates/shortcodes/tweet.html @@ -1,4 +1,4 @@ -{{- $pc := .Page.Site.PrivacyConfig.Tweet -}} +{{- $pc := .Page.Site.Config.Privacy.Tweet -}} {{- if not $pc.Disable -}} {{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }} {{- end -}} \ No newline at end of file diff --git a/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html b/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html index bd021376d..77dceed3d 100755 --- a/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html +++ b/tpl/tplimpl/embedded/templates/shortcodes/vimeo.html @@ -1,4 +1,4 @@ -{{- $pc := .Page.Site.PrivacyConfig.Vimeo -}} +{{- $pc := .Page.Site.Config.Privacy.Vimeo -}} {{- if not $pc.Disable -}} {{ if .IsNamedParams }}
diff --git a/tpl/tplimpl/embedded/templates/shortcodes/youtube.html b/tpl/tplimpl/embedded/templates/shortcodes/youtube.html index b0da600a3..bbb3fdd07 100755 --- a/tpl/tplimpl/embedded/templates/shortcodes/youtube.html +++ b/tpl/tplimpl/embedded/templates/shortcodes/youtube.html @@ -1,4 +1,4 @@ -{{- $pc := .Page.Site.PrivacyConfig.YouTube -}} +{{- $pc := .Page.Site.Config.Privacy.YouTube -}} {{- if not $pc.Disable -}} {{- $ytHost := cond $pc.PrivacyEnhanced "www.youtube-nocookie.com" "www.youtube.com" -}} {{- if $pc.Simple -}}