silverbullet icon indicating copy to clipboard operation
silverbullet copied to clipboard

Front matter schema validation

Open zefhemel opened this issue 3 years ago • 4 comments

For certain use cases it may be useful to support schema validation (e.g. based on JSON schemas or similar) for front matter. This is useful both for checking the format as well as offering suggestions, e.g. with auto complete for “enum” style values.

Conceptually, this may look as follows:

---
$schema: <URL or page reference>
attribute1: value
attribute2: value
---

If `$schema` is specified, SB would use it to validate the remaining attributes, highlight validation errors etc.

This should be implementable as a plug, except for marking validation errors inline, this would require some extra syscalls and investigation.

cc @saturninoabril

zefhemel avatar Oct 26 '22 16:10 zefhemel

We could use JSON schema: https://json-schema.org/

zefhemel avatar Oct 26 '22 16:10 zefhemel

Or: https://github.com/hay-kot/flint

zefhemel avatar Dec 01 '22 05:12 zefhemel

Something else to consider: in the past, I've continuously built "checker queries" that report to me with any files that are for example #person but don't have company: .... in their frontmatter. That way I was making sure I have consistent information. If sometimes that field is missing, my queries would get unreliable.

What I'm trying to say: We could also think about warning when there are certain things missing in frontmatter.

Your $schema-proposal already makes that viable.

Creation of files does need to be thought through though, because adding a schema by hand is a little cumbersome. Maybe suggesting already used $schema strings is a good idea? Maybe a custom plug could provide an empty state for notes which suggests different templates to choose from?

yorrd avatar Dec 04 '22 20:12 yorrd

Adding a $schema thing within the page sounds a little messy. Can this be implemented similar to Object Decorators where we can target using path or tags etc.

meain avatar Aug 04 '24 07:08 meain