I’m wondering if it’s possible to use a data template to add comments to my bookshelf page for (some of) the books I’ve finished reading. Here’s the relevant excerpt from my bookshelf (I’ve removed references to “class” so as to simplify):
{{ range .Site.Data.bookshelves.finishedreading }}
<p>
<a href="https://micro.blog/books/{{ .isbn }}">
<img src="{{ .cover_url }}" alt="{{ .title }} cover" width="100" />
{{ .author}}, <cite>{{ .title }}</cite></a></p>
{{ end }}
What I’d like to do is add a nested range which would loop through my JSON data and, where the “bktitle” from the data matches the current .title, to insert the corresponding "bkcomment”. Something along these lines:
{{ $booknote := site.Data.booknotes }}
{{ range .Site.Data.bookshelves.finishedreading }}
{{ $booktitle := printf "s" .title }}
<p>
<a href="https://micro.blog/books/{{ .isbn }}">
<img src="{{ .cover_url }}" alt="{{ .title }} cover" width="100" />
{{ .author}}, <cite>{{ .title }}</cite></a>
{{ range $booknote.mybooks }}
{{ if eq .bktitle $booktitle }}
<br>{{ .bkcomment }}
{{ end }}
{{ end }}
</p>
{{ end }}
And, finally, the JSON data looks like this:
{
"mybooks": [
{
"bktitle": "Judas 62",
"bkcomment": "Mission: Impossible meets Smiley’s People. Who said the Cold War is over? Reviewing Box 88, I said it was “a secret, rogue intelligence-and-assassination outfit”. I was wrong: we learn here that they stop short of assassination. Highly enjoyable."
},
{
"bktitle": "I Know What I Saw",
"bkcomment": "The first-person narrative of a long-term homeless man whose memory is damaged and who is sure he witnessed a murder that can’t have happened when he says it did. The brilliance of the start isn’t maintained."
}
]
}
Can this (or something like it) be made to work and, if so, will it cause any problems if I update the JSON data each time I add a book and/or comment?