forked from gohugoio/hugo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tpl/tplimpl: Deprecate twitter shortcode in favor of x shortcode
Closes gohugoio#13214
- Loading branch information
Showing
12 changed files
with
317 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 11 additions & 8 deletions
19
tpl/tplimpl/embedded/templates/shortcodes/twitter_simple.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 -}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.