@Justin_Parks Possibly. Do you have an open GH repo you can point me to? Can you do me a favor and send me an example of the metadata/front matter in a content file. When you say “taxonomy,” are you setting this up as a taxonomy in your config file or are you just talking about a key-value pair in a content file?
I’m thinking maybe the .GroupBy
will help you in this case, but I’m still not completely groking what you’re trying to get done…
<ul>
{{ range .Data.Pages.GroupBy "chapter" }}
<li>{{.Key}}</li>
{{ end }}
</ul>
But you mentioned something about sorting by date, which you could do within the pages of each group (ie, within each “chapter”) and even grab the first one as follows:
<ul>
{{ range .Site.Pages.GroupByParam "chapter" }}
{{range first 1 .Pages.ByDate.Reverse }}
<li>{{.Params.chapter}}</li>
{{ end }}
{{ end }}
</ul>
This would then print out the following per your request above:
That said, if chapters are set up as an actual taxonomy in your config.toml
file…
[taxonomies]
chapter = "chapters"
Then add chapters: The Beginning
, etc to the frontmatter/yaml/metadata of your content files.
Then you could pull up each value in the key-value (ie, chapter => chapter name) as follows within another template (I’d recommend adding this as an include if you want to repurpose it across multiple layouts:
<ul>
{{ range $chapter, $taxonomy := .Site.Taxonomies.chapters }}
<li>{{$chapter}}</li>
{{ end }}
</ul>
Also, I’m not sure what you mean by “tag cloud.” Are you trying to get the total number of pages/content files for each chapter? Is this so that you can visually show how the total number of pages are weight? Something like this? If so, I’d recommend using an actual Hugo taxonomy in your config and front matter so that you can easily pull up the total number of pages for each as follows…
<ul>
{{ range $taxonomy, $chapter := .Site.Taxonomies.chapters.ByCount }}
<li data-count="{{$chapter.Count}}">{{$chapter.Name}} </li>
{{ end }}
</ul>
Hope that helps.