I am attempting to get HUGO to output a glossary. I have a situation where, I am wanting to set frontmatter variables according to a filename (rather than having to set it manually). For example;
I have the following directory structure;
\Glossary
\Glossary\a
\Glossary\a\aardvarrk.md
\Glossary\a\apple.md
\Glossary\b
\Glossary\c
\Glossary\etc
My frontmatter variables might look like this;
—
title: “aardvark”
categories: a
type: glossary
—
My list.html template (for showing the glossary) looks like this;
<main>
<div class="container">
<div class="glossary">
<h1>Welcome to the glossary</h1>
<h3>Learn time!</h3>
<div class="footerbar">
{{ if isset .Site.Taxonomies "categories" }}
{{ if not (eq (len .Site.Taxonomies.categories) 0) }}
<div class="categories">
<ul >
<li><a href="/glossary">All</a></li>
{{ range $name, $items := .Site.Taxonomies.categories }}
<li><a href="/categories/{{ $name | urlize | lower }}">{{ $name }}</a>
</li>
{{ end }}
</ul>
</div>
{{ end }}
{{ end }}
{{ range (where .Data.Pages "Type" "glossary") }}
<a href="{{ .Permalink }}">{{ .Title }}</a>
{{end}}
</div>
</div>
</div>
</main>
My goal is so that I do not need to set the categories front matter manually (ideally the title either). I want to read it from the filename? Is such a thing possible?
Thanks pricestamp. It’s doable. I’d rather not have to do it that way if I dont have to. Can you (or anyone) think of a way that it can be done without preprocessing? (I know hugo is still pretty new, but I am sure I am not the only one who would want to achieve similar feats?)
Actually, that post is exactly what I am trying to do in another place of my website also…(was hopeing the answer to this question would lead me also to the answer for that question )
I was hoping not to have to preprocess things (it increases complexity)…but it is beginning to look like that’s the only way to do it…I’m in a windows environment so I’m going to have to adapt that script to something else, but it’ll work for sure…
I wish it was simpler…
Thank you kindly for your help, much appreciate it…
No prob. Also, if you use Git Bash for Windows, you should be able to use that script as-is (since Git Bash includes awk and many other UNIX-like utilities)