Hi! I’m having issues storing and retrieving information from the global Hugo scratch pad as documented here: hugo.Store. I’m not a programmer, so I don’t even how to describe what’s going wrong very well; please bear with me.
The thing that I intend to do is this: Lots of different posts on my blog end with Links sections. I would like to be able to wrap the content of each Links section in a shortcode which gathers up all the links in that section, so that they can be dumped on a Bookmarks page elsewhere.
Here’s what I’ve tried so far: I have two shortcodes gather
and dump
which are implemented as follows:
gather.html
{{/* gather the relevant information in the global scratchpad named $dest */}}
{{ $dest := .Get "dest" }}
{{ $exists := hugo.Store.Get $dest }}
{{ if not $exists }}
{{ hugo.Store.Set $dest .Inner }}
{{ else }}
{{ hugo.Store.Add $dest .Inner }}
{{ end }}
{{ .Inner | safeHTML }}
dump.html
:
{{/* dump the relevant information from the global scratchpad named $source */}}
{{ $source := .Get "source" }}
{{ hugo.Store.Get $source | safeHTML }}
The issue that I’m running in to is this: When I actually try to use gather
and dump
, I get this weird result where dump
produces many copies of the information which was gather
-ed up. Moreover, it seems that the dump
also has old versions of the content in global scratch pad. (See screenshot below.)
I put a minimal example on Github here:
For example, this is what I see when running the minimal example locally using hugo server
.
For what it is worth, here is my hugo env
output:
hugo v0.144.0-b289b17c433aa8ebf8c73ebbaf4bed973ac8e4d5 linux/amd64 BuildDate=2025-02-17T16:22:31Z VendorInfo=gohugoio
GOOS="linux"
GOARCH="amd64"
GOVERSION="go1.24.0"
Many thanks for your patience and support!