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.