I wrote a shortcode that uses <script>
and <style>
tags, and I dont want to apply them in the html every time I call it. Only the first call should add those tags, while subsequent calls shouldnt, as the tags are already included after the first call.
I read about Store
and Scratch
and that, now, it is aliased. Using it, I wrote:
{{- if not (.Page.Store.Get "myCounter") -}}
<script type="text/javascript" src= '(...)'></script>
<style>(...)</style>
{{- end -}}
{{- .Page.Store.Add "myCounter" 1 -}}
It works properly when using hugo
or at the first build of hugo serve -w
. However, in subsenquently builds, it break, The.Page.Store
value doesnt reset between builds.
For example, during the first build, myCounter
starts at 0. When I call the shortcode it adds one. In the next build, myCounter
starts at 1, so it doesnt add the tags, and the shortcode breaks. This behavior continues, incrementing myCounter
each time, so subsequent builds start with higher values
I dont think its expected behaviour. Shouldnt hugo serve -w
act like a watch dog, and running hugo serve
for every change? I dont write it as a issue because I think that maybe Scratch
had the behaviour I expect. But since it got deprecated, it should be somewhere else.
Therefore, what would be the proper way to write this functionality?
I tried the flags --noHTTPCache
and --disableFastRender
, same behaviour.