I am using the ‘hugo-notice’ shortcode to render a ‘notice’ admonition. This shortcode uses .Page.Scratch to include the required CSS only on the first instance per page. It checks if a special variable is set in .Page.Scratch. If not, it renders the CSS and sets the variable.
I noticed that when running in server mode and I change a different page, the shortcode is re-rendered, but the .Page.Scratch is not reset, so the CSS is not included (and so the notice appears unstyled). However, if I modify the current page, it clears the .Page.Scratch and re-renders the shortcode correctly.
Is this the correct behavior of .Page.Scratch? Is there a way to have a scratchpad that will be reset when the page is rebuilt (even if it is another file that is modified)?
(Edit: I also tried with .Page.Store and it has the same behavior)
I don’t know enough about .Page.Scratch to answer the question directly, but perhaps it’s possible to do without it in the shortcode. I’ll see what’s possible as soon as I have time
If anyone has any suggestions, please let us know.
Hi everyone, thanks for the responses. There is no difference for me between Scratch and Store. When creating a reproducer, I noticed that this looks like it is an interaction between hugo-book and hugo-notice.
I would start by raising an issue with the author of the hugo-book theme, because I can reproduce the problem using their “mermaid” and “katex” shortcodes, both of which use a similar mechanism to include js/css.
As others already pointed out, the behavior of the scratchpad has been altered to be this way, so yes, it is working as intended (unfortunately IMHO).
There is an open feature request to add the ability to detect when a page is being rebuild. This way one could achieve the old behavior with some custom logic.