mirror of
https://github.com/gohugoio/hugo.git
synced 2025-09-02 22:52:51 +02:00
Reimplement and simplify Hugo's template system
See #13541 for details. Fixes #13545 Fixes #13515 Closes #7964 Closes #13365 Closes #12988 Closes #4891
This commit is contained in:
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 := 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 "ctx" .) -}}
|
||||
{{- 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" $.ctx.Name $.ctx.Position -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
||||
{{- end -}}
|
Reference in New Issue
Block a user