contentlayerdev / contentlayerdev/contentlayer

Provide a resolve key on fields to generate a default value when one is not provided

Open
#275 1 comment 0 reactions 0 assignees View on GitHub
feature meta: never-stale pkg/source-files
Dominant language
TypeScript
Stars
3.5k
Forks
192
PR merge metrics
No merged PRs in 30d

Description

My idea is to add a `resolve` key to the fields, so that when a value is not provided for that field the resolve function will fire, which then creates a default value for the field instead.

So for example I might have the following:

```
fields: {
title: {
type: 'string',
description: 'The title of the post',
required: true,
},
url: {
type: 'string',
description: 'The URL of the post',
required: false,
resolve: (doc: any) => `/${doc._raw.flattenedPath}`,
},
...
```

With this I can provide a URL value in the frontmatter of the markdown file if I am interested in providing a very specific URL for something, but otherwise it will generate the field automatically.

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.