Problems with 0.141.0 and tweet / x embed

After upgrading from 0.140.0 to 0.141.0, and replacing all my tweet embeds with {{< x user=“username” id=“id” >}} I’ve run into another problem when rendering my site:

Error: error building site: render: failed to render pages: render of "/Users/h0bbel/GitHub/vninja/content/post/VMware-Updates-vSAN8-ESA-Requirements.md" failed: "/Users/h0bbel/GitHub/vninja/themes/hugo-bootstrap-premium/layouts/_default/single.html:40:9": execute of template failed: template: _default/single.html:40:9: executing "_default/single.html" at <.Render>: error calling Render: failed to execute template _default/single.content.html: "/Users/h0bbel/GitHub/vninja/themes/hugo-bootstrap-premium/layouts/_default/single.content.html:1:3": execute of template failed: template: _default/single.content.html:1:3: executing "_default/single.content.html" at <partial "bloc/content/content.html" .>: error calling partial: "/Users/h0bbel/GitHub/vninja/themes/hugo-bootstrap-premium/layouts/partials/bloc/content/content.html:11:5": execute of template failed: template: partials/bloc/content/content.html:11:5: executing "partials/bloc/content/content.html" at <.Content>: error calling Content: "/Users/h0bbel/GitHub/vninja/content/post/VMware-Updates-vSAN8-ESA-Requirements.md:28:1": failed to render shortcode "x": failed to process shortcode: template: _internal/shortcodes/x.html:26:106: executing "render-x" at <.name>: can't evaluate field name in type template.TryValue

Obviously it’s related to the shortcode (and removing the shortcodes makes it render), but I’m a bit lost as to how to actually fix the issue. I got the same problem with the old tweet shortcode as well, after updating and I had hoped that replacing them with the new one for x would fix it. Sadly, it did not.

Any pointers?

Yeah, that’s a bug, and we’ll fix it.

I think what’s triggering this is that X is returning a 404 for one or more of your posts. Do you have a lot of them?

Ah, then I don’t. have to pull more of my greys out trying to figure it out :wink:

I have quite a few, amassed over a number of years

❯ grep -R "{{< x" content/* | wc -l
     355

There might very well be a 404 somewhere there, but going through that manually won’t be any fun, also that means future 404’s might break this anyway…

You’ve got a couple of choices:

  1. Wait until the next release… it will include a fix for this. You will still have errors, but it will tell you the position (page, line, column) of the offending shortcode call.

  2. Override the embedded template.

Let me know if you wish to pursue #2.

Would you mind testing this for me?

layouts/shortcodes/x.html
{{- $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 -}}


1 Like

For now I’m happy with waiting for the next release. My live site is running 0.140.0 now anyway, since upgrading it on Netlify breaks it. For now it’s just my local instance that’s not working. That’s not a problem at all, until I decide to post something new. I could also revert all my shortcodes again, and downgrade to 0.140.0, which works (no fun in doing that, but sed gets me a long way :slight_smile: ).

So I guess it depends on the timeframe for a fix?

Oh, didn’t see that! Let me do that real quick.

Created the layouts/shortcodes/x.html but it still errors out, with this:

hugo v0.141.0+extended+withdeploy darwin/arm64 BuildDate=2025-01-16T13:11:18Z VendorInfo=brew

Built in 2355 ms
Error: error building site: render: failed to render pages: render of "/Users/h0bbel/GitHub/vninja/content/post/2013-10-29-microsoft-fair-balanced.md" failed: "/Users/h0bbel/GitHub/vninja/themes/hugo-bootstrap-premium/layouts/_default/single.html:40:9": execute of template failed: template: _default/single.html:40:9: executing "_default/single.html" at <.Render>: error calling Render: failed to execute template _default/single.content.html: "/Users/h0bbel/GitHub/vninja/themes/hugo-bootstrap-premium/layouts/_default/single.content.html:1:3": execute of template failed: template: _default/single.content.html:1:3: executing "_default/single.content.html" at <partial "bloc/content/content.html" .>: error calling partial: "/Users/h0bbel/GitHub/vninja/themes/hugo-bootstrap-premium/layouts/partials/bloc/content/content.html:11:5": execute of template failed: template: partials/bloc/content/content.html:11:5: executing "partials/bloc/content/content.html" at <.Content>: error calling Content: "/Users/h0bbel/GitHub/vninja/content/post/2013-10-29-microsoft-fair-balanced.md:37:1": failed to render shortcode "x": failed to process shortcode: "/Users/h0bbel/GitHub/vninja/layouts/shortcodes/x.html:9:31": execute of template failed: template: shortcodes/x.html:9:31: executing "shortcodes/x.html" at <dict "id" $id "user" $user "dnt" $pc.EnableDNT "name" "ctx" $>: error calling dict: invalid dictionary call

Yeah, I typed too quickly. I’ve updated it. Please try again, thanks.

Yes, that works, with warnings:

WARN  The "x" shortcode was unable to retrieve the remote data. See "/Users/h0bbel/GitHub/vninja/content/post/2015-02-02-great-disturbance-force.md:27:1"
You can suppress this warning by adding the following to your site configuration:
ignoreLogs = ['shortcode-x-getremote']

That’s great, thanks! Should I just leave that there, even when a fix is in place at a later point?

You can leave it there, though if it were me I’d put on note on my calendar to remove it in a month or so. Follow the progress here:

https://github.com/gohugoio/hugo/issues/13279
https://github.com/gohugoio/hugo/pull/13281

Great! Thanks for the help!

Saw that 0.142.0 was available, so I removed the /layouts/shortcodes/x.html file, upgraded and so far so good! Thanks again for fixing it upstream.

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.