Support DNT in Twitter shortcode for GDPR

Fixes #4765
This commit is contained in:
Bjørn Erik Pedersen 2018-05-24 12:25:52 +02:00
parent 3bfe8f4be6
commit 9753cb59f1
No known key found for this signature in database
GPG key ID: 330E6E2BD4859D8F
4 changed files with 12 additions and 2 deletions

View file

@ -67,6 +67,10 @@ type SpeakerDeck struct {
// 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.

View file

@ -41,6 +41,7 @@ simple = true
disable = true
[privacy.twitter]
disable = true
enableDNT = true
[privacy.vimeo]
disable = true
[privacy.youtube]
@ -62,6 +63,7 @@ simple = true
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)

View file

@ -365,7 +365,9 @@ 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 -}}`},
{`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 -}}

View file

@ -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 -}}