I have this error when trying to render a tweet, or “x”

Hello,

I have this error when trying to render a tweet, or “x”, I have the file with the same name x.html

I have followed these steps,

I also have the extended version of hugo 0.143.0

“/src/layouts/shortcodes/x.html:20:1”: parse failed: template: shortcodes/x.html:20: function “try” not defined

Are you sure? Type hugo version and paste the results here.

Are you building your site locally and remotely (e.g., Netlify, GitHub Pages)? If yes, do have the same error in both places?

Please share your x.html file…

Sorry doc,

hugo v0.143.0-ee48d9692af281180aea00645d86f3231a5231df+extended linux/amd64 BuildDate=2025-02-01T15:56:04Z VendorInfo=gohugoio

Locally it works perfectly for me,

The problem is in my github action

This is the action

The x file

{{- $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 -}}

Without access to your repository (action and logs) I would just be guessing.

1 Like

for the time being,

I removed this to make it work

//{{< x user=“pbakker” id=“1523421841410248704” >}}}

And x.html content too.

I just stood your site up here:
https://github.com/jmooring/boredblog

No problems.

I based the workflow on our published example.

https://github.com/jmooring/boredblog/blob/main/.github/workflows/hugo.yaml

1 Like

You are installing hugo using the paceiris action

and later use a docker container ???

I’m not used to docker, but sounds strange to me

in your log file there’s an installation of bric3/hugo-builder (updated 4y ago to v0.82.1)
and this has a dockerfile which readds like this:

linbes 29++
ARG HUGO_VERSION=0.82.1

# Downloading latest manually as packages are a bit dated
RUN mkdir -p /usr/local/hugo \
  && curl -LO https://github.com/gohugoio/hugo/releases/download/v${HUGO_VERSION}/hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz \
  && tar xzvf hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz -C /usr/local/hugo/ \
  && ln -s /usr/local/hugo/hugo /usr/local/bin/hugo \
  && rm hugo_extended_${HUGO_VERSION}_Linux-64bit.tar.gz

There is no logfile for the run, so are you sure you are using the hugo installed in the WF?
and if not, are you sure your docker container is up to date?

guess you will have to chack your docker run logfiles, and maybe print out more info eg the version :wink:

1 Like

Totally, I’m sure it was the outdated docker image…

But now everything works with the latest version.

I’ve removed the test repo.

1 Like

What I do notice is that Action deployment times have tripled.

Could it be that the docker image was faster?

It would be worth updating that image as far as I can see.

could be that docker containers are cached… so all that installation stuff is already there… asciidoc, ruby, hugo, …

or the startup is faster than installing in a runner

remember one may cache a runner…not sure

you’ll have to check that in the github docs.

1 Like

thanks a lot my friend.

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