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.

 1{{ if in .Params.tags "100DaystoOffload" }}
 2{{ $todaydate := .Params.Date }}
 3{{ $posts := where .Site.Pages "Type" "post" }}
 4{{ $.Scratch.Set "tagCounter" 0 }}
 5    {{ range $posts}}
 6        {{ if in .Params.tags "100DaystoOffload" }}
 7            {{ if gt $todaydate .Params.Date }}
 8                {{ $.Scratch.Add "tagCounter" 1 }}
 9            {{ end }}
10        {{ end }}
11    {{ end }}
12<div class="tagscounter">
13    Post {{ $.Scratch.Get "tagCounter" }}/100 - part of <a href="">100DaystoOffload
15{{ 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.


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