Hugo freezes - timed out initializing value

this code prevents Hugo server to start. Setting timeout limit in config not helping. I have over 200 posts with this shortcode.

There is no error with less posts using this shortcode.

Error:

timed out initializing value. You may have a circular loop in a shortcode, or your site may have resources that take longer to build than the `timeout` limit in your Hugo config file.

the shortcode:

{{ $path := .Get "url" }}
{{$page := .Site.GetPage $path}}
<figure class="fg-bookmark"><a href="{{$page.RelPermalink}}"><div class="fg-bookmark-content"><div class="fg-bookmark-title">{{ $page.Title }}</div><div class="fg-bookmark-description">{{ $page.Summary }}</div><div class="fg-bookmark-website"><img src="/icons/favicon/favicon-16x16.png" class="fg-bookmark-icon"><span class="fg-bookmark-sitename">{{ site.Title }}</span></div></div>
    <div class="fg-bookmark-thumbnail">
        {{ $original := path.Base $page.Params.image }}
        {{ $originalImg := $page.Resources.GetMatch $original }}
        {{ if $originalImg }}
            {{ printf `<img src="%s" alt="%s">` 
                $originalImg.RelPermalink $page.Title | safeHTML }}
        {{end}}
    </div></a>
</figure>

What are you trying to do? Insert a post stub with image on a page?

{{ $path := .Get "url" }}
{{- with .Site.GetPage $path }}
<figure class="fg-bookmark"><a href="{{.RelPermalink}}"><div class="fg-bookmark-content"><div class="fg-bookmark-title">{{ .Title }}</div><div class="fg-bookmark-description">{{ .Summary }}</div><div class="fg-bookmark-website"><img src="/icons/favicon/favicon-16x16.png" class="fg-bookmark-icon"><span class="fg-bookmark-sitename">{{ site.Title }}</span></div></div>
    <div class="fg-bookmark-thumbnail">
      {{- if .Params.image }}
      {{- $src := .Resources.GetMatch .Params.image }}
        {{ if $src }}
        <img src="{{- ($src.Resize "160x jpg q75").RelPermalink }}">
        {{ end }}
      {{ end }}
    </div></a>
</figure>
{{ end }}

I don’t see this in your snippet, but the “circular loop” in question is when you in a shortcode end up including yourself …

So, in a shortcode

  • {{ .Page.Content }} returns a blank string for this reason.
  • {{ (site.GetPage .Page.Path).Content }} (assuming I got it right) will end up in an infinite recursion.

As I said, I’m not sure what’s happening in your situation, but I suspect it’s something we’re not seeing. Do you have the source somewhere for people to look at? (e.g. GitHub).

P.S. It is Hugo on Windows.

.Page.Content isn’t used in this shortcode, only Front Matter data and general site settings. All posts have relevant Front Matter data.

Do you think {{- with .Site.GetPage $path }} is too complex way for this shortcode. Is there any alternative to this solution, or should I come back to fetch various data from .Get shortcode fields typed manually? (manually typed page title, image link, description etc. works).

Each post has facy link to other content (other post) thanks to this shortcode - which is placed inside post content. First version of the shortcode needed to put title, summary, image data manually and I thought that I could make the process easier for the user, who would just put URL of the other interesting post.

I think I will come back to the first “manual” version as Hugo aren’t able to manage this code.

the bookmark shortcode in post looks like this:

{{< bookmark url="/postname" title="Post title" description="some description" icon="/images/favicon.png" publisher="Site Name" thumbnail="imagepath.jpg">}}

All data where used in the past, but now wanted to simplified the shortcode, so only URL is used and other data fetched automatically. As you can see unused bookmark data are e.g. title, description. Do you think it would cause the confict with Front Matter “Title” setting of the bookmarked post and .GetPage function for instance?

My edit of your code worked fine for me, perhaps it is the inclusion of the page summary that could contain the shortcode and cause a loop.

It is Summary that cause the error. It has no shortcode. I removed some symbols from posts Summary, but still Hugo freezes. Is there any way to check what causes the Hugo freeze exactly?

Have you tried using plainify or safeHTML for the .summary ?
I’d love to learn more about debugging also but I’ve managed so far by doing things like starting with a minimal working set of content and then adding more in small amounts.

See:
https://discourse.gohugo.io/t/you-may-have-a-circular-loop-in-a-shortcode-problem/39183/2

plainify and safeHTML are not the solution

Thanks for the link. Does it mean, I cannot do anything about it?

A circular loop is… a circular loop.

:chicken: → :egg: → :chicken: → :egg: → :chicken: → :egg: → …

The solution is… don’t do that.

1 Like