Kishore Vancheeshwaran
Auto count posts for 100DaystoOffload

I wanted to keep track of the posts I write for the 100DaysToOffload challenge. I wrote the following snippet to include in all my posts which have the tag 100daystooffload. Now I don’t have to end up wondering which post I’m at when I write it at the bottom of my posts.

{{ if in .Params.tags "100DaystoOffload" }}
{{ $todaydate := .Params.Date }}
{{ $posts := where .Site.Pages "Type" "post" }}
{{ $.Scratch.Set "tagCounter" 0 }}
    {{ range $posts}}
        {{ if in .Params.tags "100DaystoOffload" }}
            {{ if gt $todaydate .Params.Date }}
                {{ $.Scratch.Add "tagCounter" 1 }}
            {{ end }}
        {{ end }}
    {{ end }}
<div class="tagscounter">
    Post {{ $.Scratch.Get "tagCounter" }}/100 - part of <a href="https://100daystooffload.com/">100DaystoOffload
</div>
{{ end }}

I tried making it a partial but I couldn’t do it. I guess I don’t understand the scoping/context/syntax of go’s templating that well yet. For now this is hardcoded in my single.html. If anyone can help me get this into a partial, please do email me. I would love to learn this from you.

References

If you would like to leave a comment, contact me via email.
Post 1/99 - part of 100DaystoOffload