Statiq.Web
Statiq.Web copied to clipboard
FrontMatter seems to ignore YAML metadata with array of arrays
Got the following front matter truing to get array of arrays of string, two levels. Navigation2 gets completely missed.
Navigation1: "1"
Navigation2:
-
- "a/index.md"
- "a/a/index.md"
-
- "a/b/index.md"
-
- "a/c/index.md"
-
- "a/d/index.md"
Navigation3: "2"
Later in Razor:
Console.WriteLine(" [+] keys:" + String.Join("\n", document.Keys));
Output:
Navigation1
Navigation3
This behavior is mostly by design. YAML is more expressive than what a typical C# object graph can hold. For example, imagine if you also mixed in a few named properties alongside the nested arrays - there’s no good way to represent that beyond making an anonymous or dynamic object. To avoid these kinds of problems and keep the default YAML behavior simple, it only places top-level scalars into the metadata.
There is an alternative - you can use the alternate Yaml module constructor that has a metadata key parameter. Setting that will place the entire YAML model as a dynamic object into the specified key. From there you should be able to access the full YAML data include more complex values.
My FrontMatter from my original Jekyll setup looks like this, and I'm having trouble figuring out how to port it over to the Razor template:
---
title: Find The Middle
nav:
- { url: "index.html", title: "Lessons" }
outline-header: Lessons
outline:
- { url: "#objective", title: "Objective" }
- { url: "#config", title: "Suggested Configuration" }
- { url: "#resources", title: "Resources" }
- { url: "#classroom", title: "Classroom Notes" }
- { url: "#commands", title: "Commands Used" }
- { url: "#api", title: "API Used" }
---
In Jekyll templates I could just check for existance page.outline
{% for item in page.outline %}
<li><a href="{{ item.url }}">{{ item.title }}</a></li>
{% endfor %}
But trying to make a foreach
in Razor off the parsed Yaml Metadata object seems a lot more complicated? What am I missing?
This Yaml Module page mentions configuring it somehow, is that in the config.wyam
? And there's no link to the documentation on how to actually access it afterwards as a YamlDotNet.Dynamic
object; searching for that brings up a repo about it but with no docs.
Examples of accessing this data in a simple manner would be great. Even if I have to create a struct/class somewhere to strongly type it, I'm fine with that if it means I can access things directly later.