mirror of
https://github.com/gohugoio/hugo.git
synced 2025-08-30 22:39:58 +02:00
tpl/tplimpl: Deprecate twitter shortcode in favor of x shortcode
Closes #13214
This commit is contained in:
committed by
Bjørn Erik Pedersen
parent
60c24fc5ee
commit
1191467c05
@@ -1,3 +1,4 @@
|
||||
{{- warnf "The \"twitter\", \"tweet\", and \"twitter_simple\" shortcodes were deprecated in v0.142.0 and will be removed in a future release. Please use the \"x\" shortcode instead." }}
|
||||
{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
|
||||
{{- if not $pc.Disable -}}
|
||||
{{- if $pc.Simple -}}
|
||||
|
@@ -1,34 +1,37 @@
|
||||
{{- $pc := .Page.Site.Config.Privacy.Twitter -}}
|
||||
{{- $sc := .Page.Site.Config.Services.Twitter -}}
|
||||
{{- if not $pc.Disable -}}
|
||||
{{- warnf "The \"twitter\", \"tweet\", and \"twitter_simple\" shortcodes were deprecated in v0.142.0 and will be removed in a future release. Please use the \"x\" shortcode instead." }}
|
||||
{{- if not site.Config.Privacy.Twitter.Disable -}}
|
||||
{{- $id := or (.Get "id") "" -}}
|
||||
{{- $user := or (.Get "user") "" -}}
|
||||
{{- if and $id $user -}}
|
||||
{{- template "render-simple-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "name" .Name "position" .Position) -}}
|
||||
{{- template "render-simple-tweet" (dict "id" $id "user" $user "ctx" .) -}}
|
||||
{{- else -}}
|
||||
{{- errorf "The %q shortcode requires two named parameters: user and id. See %s" .Name .Position -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "render-simple-tweet" -}}
|
||||
{{- $dnt := site.Config.Privacy.Twitter.EnableDNT }}
|
||||
{{- $url := printf "https://twitter.com/%v/status/%v" .user .id -}}
|
||||
{{- $query := querify "url" $url "dnt" .dnt "omit_script" true -}}
|
||||
{{- $query := querify "url" $url "dnt" $dnt "omit_script" true -}}
|
||||
{{- $request := printf "https://publish.twitter.com/oembed?%s" $query -}}
|
||||
{{- with try (resources.GetRemote $request) -}}
|
||||
{{- with .Err -}}
|
||||
{{- errorf "%s" . -}}
|
||||
{{- else with .Value -}}
|
||||
{{- if not site.Config.Services.Twitter.DisableInlineCSS }}
|
||||
{{- template "__h_simple_twitter_css" (dict "ctx" $.ctx) }}
|
||||
{{- end }}
|
||||
{{- (. | transform.Unmarshal).html | safeHTML -}}
|
||||
{{- else -}}
|
||||
{{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
|
||||
{{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .ctx.Name .ctx.Position -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "__h_simple_twitter_css" -}}
|
||||
{{- if not (.Page.Scratch.Get "__h_simple_twitter_css") -}}
|
||||
{{- if not (.ctx.Page.Store.Get "__h_simple_twitter_css") -}}
|
||||
{{/* Only include once */}}
|
||||
{{- .Page.Scratch.Set "__h_simple_twitter_css" true -}}
|
||||
{{- .ctx.Page.Store.Set "__h_simple_twitter_css" true -}}
|
||||
<style type="text/css">
|
||||
.twitter-tweet {
|
||||
font:
|
||||
|
29
tpl/tplimpl/embedded/templates/shortcodes/x.html
Normal file
29
tpl/tplimpl/embedded/templates/shortcodes/x.html
Normal file
@@ -0,0 +1,29 @@
|
||||
{{- $pc := .Page.Site.Config.Privacy.X -}}
|
||||
{{- if not $pc.Disable -}}
|
||||
{{- if $pc.Simple -}}
|
||||
{{- template "_internal/shortcodes/x_simple.html" . -}}
|
||||
{{- else -}}
|
||||
{{- $id := or (.Get "id") "" -}}
|
||||
{{- $user := or (.Get "user") "" -}}
|
||||
{{- if and $id $user -}}
|
||||
{{- template "render-x" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "name" .Name "position" .Position) -}}
|
||||
{{- else -}}
|
||||
{{- errorf "The %q shortcode requires two named parameters: user and id. See %s" .Name .Position -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "render-x" -}}
|
||||
{{- $url := printf "https://x.com/%v/status/%v" .user .id -}}
|
||||
{{- $query := querify "url" $url "dnt" .dnt -}}
|
||||
{{- $request := printf "https://publish.x.com/oembed?%s" $query -}}
|
||||
{{- with try (resources.GetRemote $request) -}}
|
||||
{{- with .Err -}}
|
||||
{{- errorf "%s" . -}}
|
||||
{{- else with .Value -}}
|
||||
{{- (. | transform.Unmarshal).html | safeHTML -}}
|
||||
{{- else -}}
|
||||
{{- warnidf "shortcode-x-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
60
tpl/tplimpl/embedded/templates/shortcodes/x_simple.html
Normal file
60
tpl/tplimpl/embedded/templates/shortcodes/x_simple.html
Normal file
@@ -0,0 +1,60 @@
|
||||
{{- if not site.Config.Privacy.X.Disable -}}
|
||||
{{- $id := or (.Get "id") "" -}}
|
||||
{{- $user := or (.Get "user") "" -}}
|
||||
{{- if and $id $user -}}
|
||||
{{- template "render-simple-x" (dict "id" $id "user" $user "ctx" .) -}}
|
||||
{{- else -}}
|
||||
{{- errorf "The %q shortcode requires two named parameters: user and id. See %s" .Name .Position -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "render-simple-x" -}}
|
||||
{{- $dnt := site.Config.Privacy.X.EnableDNT }}
|
||||
{{- $url := printf "https://x.com/%v/status/%v" .user .id -}}
|
||||
{{- $query := querify "url" $url "dnt" $dnt "omit_script" true -}}
|
||||
{{- $request := printf "https://publish.x.com/oembed?%s" $query -}}
|
||||
{{- with try (resources.GetRemote $request) -}}
|
||||
{{- with .Err -}}
|
||||
{{- errorf "%s" . -}}
|
||||
{{- else with .Value -}}
|
||||
{{- if not site.Config.Services.X.DisableInlineCSS }}
|
||||
{{- template "__h_simple_x_css" (dict "ctx" $.ctx) }}
|
||||
{{- end }}
|
||||
{{- (. | transform.Unmarshal).html | safeHTML -}}
|
||||
{{- else -}}
|
||||
{{- warnidf "shortcode-x-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .ctx.Name .ctx.Position -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
|
||||
{{- define "__h_simple_x_css" -}}
|
||||
{{- if not (.ctx.Page.Store.Get "__h_simple_x_css") -}}
|
||||
{{/* Only include once */}}
|
||||
{{- .ctx.Page.Store.Set "__h_simple_x_css" true -}}
|
||||
<style type="text/css">
|
||||
.twitter-tweet {
|
||||
font:
|
||||
14px/1.45 -apple-system,
|
||||
BlinkMacSystemFont,
|
||||
"Segoe UI",
|
||||
Roboto,
|
||||
Oxygen-Sans,
|
||||
Ubuntu,
|
||||
Cantarell,
|
||||
"Helvetica Neue",
|
||||
sans-serif;
|
||||
border-left: 4px solid #2b7bb9;
|
||||
padding-left: 1.5em;
|
||||
color: #555;
|
||||
}
|
||||
.twitter-tweet a {
|
||||
color: #2b7bb9;
|
||||
text-decoration: none;
|
||||
}
|
||||
blockquote.twitter-tweet a:hover,
|
||||
blockquote.twitter-tweet a:focus {
|
||||
text-decoration: underline;
|
||||
}
|
||||
</style>
|
||||
{{- end -}}
|
||||
{{- end -}}
|
Reference in New Issue
Block a user