contentlayerdev / contentlayerdev/contentlayer

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

Aperta
#275 1 commento 0 reazioni 0 assegnatari Vedi su GitHub
feature meta: never-stale pkg/source-files
Lingua principale
TypeScript
Stelle
3.5k
Fork
192
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

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.

Guida per i contributori

Apri la guida per i contributori

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.