Hugo fails to build when pages reference each other

I’m using the following shortcode to create article previews:

{{$linktext := .Get 0}}
{{$page := .Site.GetPage (.Get 1)}}
<a class="internal-link" href="{{$page.RelPermalink}}" alt="{{$page.Title}}">{{$linktext}}</a>
<span class="link-preview">
<span class="link-title">{{$page.Title}}<br></span>
<span class="link-summary">{{$page.Summary | plainify }}</span>
</span>

When I use this shortcode, if I have any posts that reference each other (e.g. Page A has a link to Page B and Page B has a link to Page A), hugo throws the following 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 thetimeout limit in your Hugo config file.

It appears that {{$page.Summary}} is the culprit; if I remove this from my shortcode, Hugo builds and serves without issue. (Manually adding summary content in the frontmatter doesn’t seem to solve the problem, either.)

Does anyone know a)why this is happening, b)how I can better diagnose it, or c)how to fix it?

The following page variables force evaluation of a page’s RawContent:

  • Content
  • FuzzyWordCount
  • Len
  • Plain
  • PlainWords
  • ReadingTime
  • Summary (regardless of how you define it)
  • Truncated
  • WordCount

Page A is trying to evaluate the RawContent of Page B, which is trying to evaluate the RawContent of Page A, which is trying to evaluate the RawContent of Page B, etc.

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

The error message explains this:

circular loop in a shortcode

To avoid this…

  1. Access the summary front matter field via .Params.Summary, OR
  2. Create a front matter variable to store the preview text, OR
  3. Use the predefined description page variable.
1 Like

Thanks.
Just to confirm, it looks any working solution will require manually entering content into the frontmatter, right (whether it’s .Params.Summary, .Description, or some other variable I create)?

it looks any working solution will require manually entering content into the frontmatter

Correct.

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