11ty/eleventy-navigation

Add support for tabs in front matter

patrikalienus opened this issue · 4 comments

Not sure if this is a bug or as designed, but I didn't find it among the issues here, so I figured I'd mention it.

This does not work:

---
eleventyNavigation:
	key: Home
	order: 1
---

but this does:

---
eleventyNavigation:
  key: Home
  order: 1
---

As someone who uses tabs for all indentation everywhere, this is quite... annoying. Especially as auto-indent adjusts to tabs .

Sorry this is a hard requirement of YAML. Feel free to switch to use another front matter format—or add your own! https://www.11ty.dev/docs/data-frontmatter/#alternative-front-matter-formats

Alternatively, you can use a separate template data file too https://www.11ty.dev/docs/data-template-dir/

This caught me too, very frustrating. Maybe you should add a note about this on the navigation plugin page?

Here's a really disgusting hack if you wish to use tabs in Yaml:

import yaml from "js-yaml";

// Add support for tab indentation in YAML front matter
eleventyConfig.setFrontMatterParsingOptions({
	engines: {
		yaml: function(frontMatter) {
			return yaml.load(frontMatter.replaceAll("\t", "  "));
		}
	}
});

I should probably make it only replace tabs at the start of the line