shithub: hugo

Download patch

ref: 9753cb59f1f1d866943a485dd7c917d1b68f6eda
parent: 3bfe8f4be653f44674293685cb5750d90668b2f6
author: Bjørn Erik Pedersen <[email protected]>
date: Thu May 24 08:25:52 EDT 2018

Support DNT in Twitter shortcode for GDPR

Fixes #4765

--- a/config/privacy/privacyConfig.go
+++ b/config/privacy/privacyConfig.go
@@ -67,6 +67,10 @@
 // Twitter holds the privacy configuration settingsrelated to the Twitter shortcode.
 type Twitter struct {
 	Service `mapstructure:",squash"`
+
+	// When set to true, the Tweet and its embedded page on your site are not used
+	// for purposes that include personalized suggestions and personalized ads.
+	EnableDNT bool
 }
 
 // Vimeo holds the privacy configuration settingsrelated to the Vimeo shortcode.
--- a/config/privacy/privacyConfig_test.go
+++ b/config/privacy/privacyConfig_test.go
@@ -41,6 +41,7 @@
 disable = true
 [privacy.twitter]
 disable = true
+enableDNT = true
 [privacy.vimeo]
 disable = true
 [privacy.youtube]
@@ -62,6 +63,7 @@
 	assert.True(pc.Instagram.Simple)
 	assert.True(pc.SpeakerDeck.Disable)
 	assert.True(pc.Twitter.Disable)
+	assert.True(pc.Twitter.EnableDNT)
 	assert.True(pc.Vimeo.Disable)
 
 	assert.True(pc.YouTube.PrivacyEnhanced)
--- a/tpl/tplimpl/embedded/templates.autogen.go
+++ b/tpl/tplimpl/embedded/templates.autogen.go
@@ -365,7 +365,9 @@
 {{- end -}}`},
 	{`shortcodes/twitter.html`, `{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
 {{- if not $pc.Disable -}}
-{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}
+{{ $url := printf "https://api.twitter.com/1/statuses/oembed.json?id=%s&dnt=%t" (index .Params 0) $pc.EnableDNT }}
+{{ $json := getJSON $url }}
+{{ $json.html | safeHTML }}
 {{- end -}}`},
 	{`shortcodes/vimeo.html`, `{{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
 {{- if not $pc.Disable -}}
--- a/tpl/tplimpl/embedded/templates/shortcodes/twitter.html
+++ b/tpl/tplimpl/embedded/templates/shortcodes/twitter.html
@@ -1,4 +1,6 @@
 {{- $pc := .Page.Site.Config.Privacy.Twitter -}}
 {{- if not $pc.Disable -}}
-{{ (getJSON "https://api.twitter.com/1/statuses/oembed.json?id=" (index .Params 0)).html | safeHTML }}
+{{ $url := printf "https://api.twitter.com/1/statuses/oembed.json?id=%s&dnt=%t" (index .Params 0) $pc.EnableDNT }}
+{{ $json := getJSON $url }}
+{{ $json.html | safeHTML }}
 {{- end -}}
\ No newline at end of file