Hugo.exe hanging when using parts of related content via shortcode

Hi there

Here’s a weird one… Inside articles, I want to link to specific related articles with this shortcode:
{{<preview-internal src="articles/s2s-stairs-to-success">}}

The shortcode looks like this:

{{ with .Site.GetPage (.Get "src") }}
<div class="shadow card">
    <div class="card-body">
        <div class="media">
            <div class="media-body">
                <h6><a href="{{ .RelPermalink }}" class="stretched-link">{{ .Title | markdownify }}</a></h6>
                <p>{{ .Summary | markdownify }}</p>
            </div>
        </div>
    </div>
</div>
{{ end }}

The weird thing is that when I run Hugo in the console, it seems to hang up itself. After 30s it ends saying: 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.

It gets more confusing: If I remove {{ .Summary }}, the rest suddenly works and hugo.exe runs fine. The summaries of the two related articles that reference each other contain simple text strings. The summary (and other fields, too) seem to cause a loop, the title or publishdate field on the other hand not.

I used the most recent v0.80.0. What do you make of this?

After digging deeper, I seem to have found the answer. For .Summary, Hugo parses the entire markdown file—even if there’s a dedicated summary parameter in the front matter. It does so to detect a potential manual summary divider <!--more-->.

So if you use the shortcode in one article that parses an entire second article which in return uses a shortcode to parse the first article, you have the circular loop. That’s what’s happening here.

To solve this, use .Params.summary in your shortcode to use a dedicated summary field. Then, Hugo doesn’t parse the entire file.

This leaves at least one other loophole: The variable .ReadingTime. Obviously, using this makes Hugo parse the entire referred article, too.

2 Likes

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