Skip to content

Commit

Permalink
tpl/tplimpl: Fix context in shortcode error messages
Browse files Browse the repository at this point in the history
Fixes #13279
  • Loading branch information
jmooring committed Jan 20, 2025
1 parent 1f5a15a commit b1ac7c4
Show file tree
Hide file tree
Showing 9 changed files with 347 additions and 243 deletions.
3 changes: 1 addition & 2 deletions tpl/tplimpl/embedded/templates/shortcodes/qr.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@param {string} [class] The class attribute of the img element.
@param {string} [id] The id attribute of the img element.
@param {string} [title] The title attribute of the img element.
@param {string} [loading] The loading attribute of the img element, one of lazy, or eager.
@param {string} [loading] The loading attribute of the img element, one of lazy or eager.

@returns {template.HTML}

Expand Down Expand Up @@ -49,7 +49,6 @@
{{- $title := or (.Get "title") "" }}
{{- $loading := or (.Get "loading") "" }}


{{- /* Validate arguments. */}}
{{- $errors := false}}
{{- if not $text }}
Expand Down
6 changes: 3 additions & 3 deletions tpl/tplimpl/embedded/templates/shortcodes/twitter.html
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
{{- 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 -}}
{{- $pc := site.Config.Privacy.Twitter -}}
{{- if not $pc.Disable -}}
{{- if $pc.Simple -}}
{{- template "_internal/shortcodes/twitter_simple.html" . -}}
{{- else -}}
{{- $id := or (.Get "id") "" -}}
{{- $user := or (.Get "user") "" -}}
{{- if and $id $user -}}
{{- template "render-tweet" (dict "id" $id "user" $user "dnt" $pc.EnableDNT "name" .Name "position" .Position) -}}
{{- template "render-tweet" (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 -}}
Expand All @@ -24,7 +24,7 @@
{{- else with .Value -}}
{{- (. | transform.Unmarshal).html | safeHTML -}}
{{- else -}}
{{- warnidf "shortcode-twitter-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
{{- warnidf "shortcode-twitter-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
{{- end -}}
{{- end -}}
{{- end -}}
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
{{- end }}
{{- (. | transform.Unmarshal).html | safeHTML -}}
{{- else -}}
{{- warnidf "shortcode-twitter-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" .ctx.Name .ctx.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 -}}
Expand Down
4 changes: 2 additions & 2 deletions tpl/tplimpl/embedded/templates/shortcodes/vimeo.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
{{- $pc := site.Config.Privacy.Vimeo -}}
{{- if not $pc.Disable -}}
{{- if $pc.Simple -}}
{{ template "_internal/shortcodes/vimeo_simple.html" . }}
Expand All @@ -11,4 +11,4 @@
</div>
{{ end }}
{{- end -}}
{{- end -}}
{{- end -}}
12 changes: 6 additions & 6 deletions tpl/tplimpl/embedded/templates/shortcodes/vimeo_simple.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{{- $pc := .Page.Site.Config.Privacy.Vimeo -}}
{{- $pc := site.Config.Privacy.Vimeo -}}
{{- if not $pc.Disable -}}
{{- $ctx := dict "page" .Page "pc" $pc "name" .Name "position" .Position }}
{{- $ctx := dict "ctx" . }}
{{- if .IsNamedParams -}}
{{- with .Get "id" -}}
{{- $ctx = merge $ctx (dict "id" . "class" ($.Get "class")) -}}
Expand All @@ -19,7 +19,7 @@
{{- end -}}

{{- define "render-vimeo" -}}
{{- $dnt := cond .pc.EnableDNT 1 0 -}}
{{- $dnt := cond site.Config.Privacy.Vimeo.EnableDNT 1 0 -}}
{{- $url := urls.JoinPath "https://vimeo.com" .id -}}
{{- $query := querify "url" $url "dnt" $dnt -}}
{{- $request := printf "https://vimeo.com/api/oembed.json?%s" $query -}}
Expand All @@ -32,21 +32,21 @@
{{- with $.class -}}
{{- $class = printf "%s %s" "s_video_simple" . -}}
{{- else -}}
{{ template "__h_simple_css" $.page }}
{{ template "__h_simple_css" $.ctx.Page }}
{{- end -}}
{{- $thumbnail := .thumbnail_url -}}
{{- $original := $thumbnail | replaceRE "(_.*\\.)" "." -}}
<div class="{{ $class }}">
<a href="{{ .provider_url }}{{ .video_id }}" rel="noopener" target="_blank">
<img src="{{ $thumbnail }}" srcset="{{ $thumbnail }} 1x, {{ $original }} 2x" alt="{{ .title }}">
<div class="play">
{{ template "__h_simple_icon_play" $.page }}
{{ template "__h_simple_icon_play" $.ctx.Page }}
</div>
</a>
</div>
{{- end -}}
{{- else -}}
{{- warnidf "shortcode-vimeo-simple" "The %q shortcode was unable to retrieve the remote data. See %s" .name .position -}}
{{- warnidf "shortcode-vimeo-simple" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
{{- end -}}
{{- end -}}
{{- end -}}
6 changes: 3 additions & 3 deletions tpl/tplimpl/embedded/templates/shortcodes/x.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{{- $pc := .Page.Site.Config.Privacy.X -}}
{{- $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 "name" .Name "position" .Position) -}}
{{- 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 -}}
Expand All @@ -23,7 +23,7 @@
{{- 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 -}}
{{- warnidf "shortcode-x-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
{{- end -}}
{{- end -}}
{{- end -}}
2 changes: 1 addition & 1 deletion tpl/tplimpl/embedded/templates/shortcodes/x_simple.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
{{- 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 -}}
{{- warnidf "shortcode-x-simple-getremote" "The %q shortcode was unable to retrieve the remote data. See %s" $.ctx.Name $.ctx.Position -}}
{{- end -}}
{{- end -}}
{{- end -}}
Expand Down
Loading

0 comments on commit b1ac7c4

Please sign in to comment.