contentlayerdev / contentlayerdev/contentlayer

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

オープン
#275 コメント 1 件 リアクション 0 件 担当者 0 名 GitHub で見る
feature meta: never-stale pkg/source-files
主要言語
TypeScript
スター
3.5k
フォーク
192
PR マージ指標
30日以内にマージされた PR はありません

説明

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.

コントリビューションガイド

コントリビューションガイドを開く

評価

この issue はまだ評価されていません。

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。