Shortcodes and build order?

On my Hugo site, I’ve implemented a pair of shortcodes “gather” and “dump.” The purpose of gather is to collect up a bunch of similar content, and dump puts it all in one place. However, the mechanism that I used to implement these, the global scratchpad, seems to be impacted by the order in which pages are built.

My questions are:
Can I force a particular order in which pages are built?
In particular, so that all the pages with the gather shortcode are built before the ones with dump?
If not, is there a better way to implement this gather/dump mechanism?

For further context: Usually there are lots more gathers than dumps. Currently, I use this to gather up all the bookmarks on my webpage and dump them all in one spot. That was working fine until I wanted to gather all the books and dump them on a bibliography page. It was only then that I noticed the importance of page build order. The bookmarks page populates just fine, but the bibliography page does not.

Here’s are some of the relevant details of the implementation.

gather.html

{{/* gather the relevant information in the global scratchpad named $dest */}}

{{ $dest := .Get "dest" }}
{{ $exists := hugo.Store.Get $dest }}
{{ $backlink := printf `<a class="bookmark-back-reference" href="%s">⤝ %s</a>` .Page.Permalink .Page.Title }}

{{ if not $exists }}
	{{ hugo.Store.Set $dest $backlink }}
{{ end }}

{{ hugo.Store.Add $dest .Inner }}

{{ .Inner | markdownify }}

And here is dump.html.

{{/* dump the relevant information from the global scratchpad named $dest */}}

{{ $source := .Get "source" }}

{{ if eq hugo.Environment "development" }}

✒️
This page includes content gathered from:
{{ $source }}


{{ end }}

{{ hugo.Store.Get $source | markdownify }}

Of course, I’m happy to provide more details and clarify if there are any issues.

See https://gohugo.io/functions/hugo/store/#determinate-values.

You could range over the all the pages and force rendering with a noop as described above.

Wow! That’s not the sort of thing I ever would have imagined. Lemme play with it a bit.

Thanks for the speedy response.

Yup! This worked in the end.

Initially, it really slowed down the build time from 20s to +10min. I don’t even know if the whole thing would have built eventually because I killed the process after +10min.

After that, I added a bit of logic to narrow down the scope of .Site.Pages and possible prevent an infinite loop. I don’t know if an infinite loop of .Content was the issue or not but the added logic seems to have fixed things. My website now renders in the usual ~20s.

{{ $here := .Page.Permalink }}

{{ range (where .Site.Pages ".Section" "in" (slice "notes" "blog" "main")) }}
    {{ if ne .Permalink $here }}
        {{ $noop := .Content }}
    {{ end }}
{{ end }}

And now, both the bibliography and bookmarks pages render fine.

Thanks so much!

Yeah, if you range through every page on every page… yikes. Either limit when you do it, or limit what you do it to, or both.