@Justin_Parks Sorry for the delay, but it’s been a crazy week. I think I may have a considerably DRYer solution for you:
<ul>
{{range $chap,$tax := .Site.Taxonomies.chapter}}
{{ range first 1 $tax.Pages.ByDate.Reverse}}
<li><a class="tag" href="{{.Permalink}}">{{.Title}}</a></li>
{{end}}
{{end}}
</ul>
I’m not sure if the {{.Permalink}}
is going to work within the anchor within the li
since I’m unaware of your intended site architecture. If there is a terser solution, I’m betting @digitalcraftsman has it at the ready.
Are you trying to make each list item link to the taxonomy page for the chapter OR the actual post?
What I gave you above will link directly to the post, but if you want to link to the taxonomy list page for the entire chapter, change the <li>
as follows:
<li><a href="/chapter/{{$chap}}">{{$chap | humanize | title}}</a>
<!--Assuming you want to title case the title of the chapter; if not, remove "| title"-->
Also, looking at your repo, I think you’re adding some unnecessary templating. E.g., the follwoing from your [book.html
] (https://github.com/kaigon/testsite/blob/master/layouts/partials/book.html) partial:
{{ if and (isset .Params "chapter") (and (not (eq .Params.chapter "")) (not (eq .Params.chapter nil))) }}
<div class="tags tags--chapter">
<!--<label>chapter</label>-->
{{ range .Params.chapter }}
<a href="{{ "/chapter/" }}{{ . | urlize }}" class="tag" title="books in the “{{ . }}” chapter">
<span>{{ . }}</span><i class="icon-tag" data-grunticon-embed></i>
</a>
{{ end }}
</div>
{{ end }}
I think for what you’re trying to do, you can get away with the following:
{{with .Params.chapter}}
<div class="tags tags--chapter">
{{range . }}
<a href="/chapter/{{ . | urlize }}" class="tag" title="books in the “{{ . }}” chapter">
<span>{{ . }}</span><i class="icon-tag" data-grunticon-embed></i>
</a>
{{end}}
</div>
{{end}}
It seems like title="Pages in the {{. | title }} Chapter"
would make more sense, but I don’t have access to the complete site
You’re also keeping all your single-page layouts/_default/single.html
. I think you’d be better off creating a single.html
for each respective section rather than trying to treat a partial like a layout…just a thought.