Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add hugo.BuildCount #13085

Open
bep opened this issue Nov 23, 2024 · 7 comments
Open

Add hugo.BuildCount #13085

bep opened this issue Nov 23, 2024 · 7 comments
Labels
Milestone

Comments

@bep
Copy link
Member

bep commented Nov 23, 2024

See https://discourse.gohugo.io/t/how-should-i-store-dynamic-data-in-the-page-object-hugo-serve-w/52514/2

Deprecating Page.Scratch was the right thing to do, but the example above may be a rare useful example of the old behavior.

It would be simple to add a hugo.BuildCount method (I guess starting at 1).

In the topic above, you could possibly do:

{{- if ne (.Page.Store.Get "myCounter")  hugo.BuildCount -}}
<script type="text/javascript" src= '(...)'></script>
<style>(...)<\style>
{{- end -}}
{{- .Page.Store.Set "myCounter" hugo.BuildCount -}}

/cc @jmooring

@bep bep added the Proposal label Nov 23, 2024
@bep bep added this to the v0.140.0 milestone Nov 23, 2024
@jmooring
Copy link
Member

For the use case described in the forum, isn't it sufficient to check the ordinal?

@bep
Copy link
Member Author

bep commented Nov 23, 2024

For the use case described in the forum, isn't it sufficient to check the ordinal?

The ordinal for the first foo shortcode on a page may still be ... 5, so I don't see how.

@bep
Copy link
Member Author

bep commented Nov 23, 2024

... if I remember the ordinal logic correctly:

{{< foo >}} // 0
{{< bar >}} // 1
{{< foo >}} // 2

@jmooring
Copy link
Member

jmooring commented Nov 23, 2024

For some reason I thought that number was tracked separately for each shortcode, and our (my) docs on the subject need some adjustment:

gohugoio/hugoDocs#2780

@bep
Copy link
Member Author

bep commented Nov 23, 2024

For some reason I thought that number was tracked separately for each shortcode, and our (my) docs on the subject need some adjustment.

I guess we could possibly change that logic, which would make this issue go away....

Edit: I guess it would not make this go away for nested shortcodes.

@bep bep closed this as completed Nov 23, 2024
@bep bep reopened this Nov 23, 2024
@jmooring
Copy link
Member

The forum topic related to this issue was handled with the HasShortcode method. I think my source of confusion about the shortcode Ordinal was that each render hook type keeps track of its own ordinal, and I forgot that shortcodes don't work the same way.

@doompadee
Copy link

I have an image gallery shortcode where the details data is stored in a .json file (to be lazy-loaded) and the page position of the shortcode is used for the mapping.

Page.Scratch was perfect for a custom counter (I first tried to use .Ordinal first), but for development the logic is now broken. Personally, I would prefer to have the choice between persistent and volatile storage facilities, but being able to reset my counter between builds would be welcomed as well.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants