to add styles they need. head partial posted above is unaware of styles values and names, or are they needed at all, just tries to iterate over .Scratch and find there names and values, and then bring them to <style> or <stylesheet>. Despite of the warning on .Scratch docs, i see no other methods to do that kind of things.
Well, what happens every time I call page.Scratch.SetInMap from different partials - a totally new .Scratch with [map] is created for current page, purging already existing .Scratch? Or new [map] entries are being created to .Scratch? Do you need the whole code (which contains lots of unrelated code), or just a bit more of context?
Little to no difference with .SetInMap and .Add, .Set is not needed in my case.
But big troubles come from .Scratch usage regarding Hugo render order - I was unable to guarantee that .Scratch is filled by one partial before another partial will try to .Get it. Tried to place .WordCount in all involved shortcodes, all together, or one by one - the first run looks good, but if anything is edited anywhere - I immediately get empty styles.
Basically I am assuming Hugo processes the top of baseof first, so move the generation of the CSS (and in our cases images) to the top of baseof, stash them in a page-level .Scratch, and access the .Scratch in head and body partials and shortcodes.
A test is required to confirm render order of baseof before putting that much effort into this. In fakt, the test could be runned inside existing code with adding a counter into every partial involved into .Scratch usage and printing that counter together with page and partial name into log. That way rendering order for our particular case will be revealed.