contentlayerdev / contentlayerdev/contentlayer

Add `Union` Field Type

Open
#250 3 comments 0 reactions 0 assignees View on GitHub
meta: never-stale needs-research topic: schema
Dominant language
TypeScript
Stars
3.5k
Forks
192
PR merge metrics
No merged PRs in 30d

Description

Basically, allow me to define a union of types that a field can be.

Simple example would be `string | string[]`. Config proposal:

```typescript
// ...
author: {
type: `union`,
of: [
{
type: `string`
},
{
type: `list`,
of: {
type: `string`
}
}
]
},
```

This would permit the following frontmatter:

```yaml
author: Foo Bar
# or
author:
- Foo Bar
- Baz Qux
```

If this is already possible with the existing field types, please add examples to the documentation which demonstrate how to do this, as it's not readily apparent how this can be done.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.