How to "collect" all Frontmatters used on site?

Hello to each other,

working/playing with HUGO… what a trip!

I am currently working/playing on a website about my HUGO learning.
Essentially, the website documented my learning and will also serve as a future guide.

I would like to document the frontmatter keys used and what they mean.
I use different frontmatter on different pages.
Is there a way to read all keys of all frontmatters of all (content-)files?

Thank you very much for your time, best regards

P.S. My native language is German, this text was translated automatically with DeepL Translate: The world's most accurate translator (free version)

This merges all front matter and displays the resulting object (keys and values). Ignore the values.

{{ $m := dict }}
{{ range site.AllPages }}
  {{ $m = merge $m .Params }}
{{ end }}
<pre>{{ jsonify (dict "indent" "  ") $m }}</pre>

The following keys will always be present, even if you have not explicitly added them to front matter:

  • draft
  • iscjklanguage

If front matter includes date, the following keys will always be present, even if you have not explicitly added them to front matter:

  • lastmod
  • publishdate
2 Likes

Thank you @jmooring,

your code gives me the information I am looking for.
Reading your code I get an idea what could be meant by the explanations about “dict” and “merge” in the documentation… Special thanks for your explanatory words about the not explicitly set frontmatters.

My ideal:
The shortcode writes the “keys” to a file.
In this file I document the task of each “key” (frontmatters).

Is it possible to keep this file up to date using shortcode?
In particular, is it possible to add new “keys” without changing the existing “keys” and their explanations?

Many greetings

Hugo can only create files in the publishDir (typically public).

I suppose you could combine the parsing code with a data file for the key descriptions, but I think the cost of trying to automate this far exceeds the value delivered. Remember that .Page.Params can contain scalars, objects, arrays, and nested combinations – the structure is not trivial.

If it were me, I would maintain the documentation manually.

Hello @jmooring,

Thanks for your quick reply and your assessment.

When you say “the structure is not trivial” then it is beyond my capabilities.
And when you say you “would maintain the documentation manually” then I definitely do.

And there are so many other adventures to experience, e.g. I learn a lot about “dict” and “merge” thanks to your code example. Also I want to finally understand this taxonomy thing.

Thanks again and best regards

1 Like

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.