How do I validate my website’s frontmatter to ensure
- No unknown keys - this can catch typo e.g. “alises” instead of “aliases”
- No incorrect types - e.g. string instead of array of string for “aliases”
How do I validate my website’s frontmatter to ensure
We do some front matter validation on the docs site:
As you can see from the first reference above, we only run it once (when building the home page).
In your situation I would create a slice of valid front matter fields, then range through all pages (outside loop) and front matter parameters (inside loop) and compare with the slice.
You can test data types using printf
with the %T
verb , reflect.IsMap
, and reflect.IsSlice
.
There’s no need to test .Aliases
as the value is cast to []string
.
Using Remark with a frontmatter extension.
Not sure how versed you are in these things, here is the short version of my setup:
---
'$schema': /static/_schemata/blog.schema.yaml
title: {{ replace .Name "-" " " | title }}
linkTitle: {{ replace .Name "-" " " | title }}
description: ""
summary: ""
---
Remark is in generally good for everything where your search query contains “markdown”.
This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.