contentlayerdev / contentlayerdev/contentlayer
Combine `fields` and `computedFields`
- 主要言語
- TypeScript
- スター
- 3.5k
- フォーク
- 192
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
Today we have `fields` and `computedFields`. The definitions in `computedFields` expects a function to which Contentlayer passes the processed document.
I'd rather be able to define all my fields in one place and allow the options of that field definition (presence of `resolve`) to determine whether or not it should be computed. Thus, I could have a doc type def like this:
```js
const Page = defineDocumentType(() => ({
// ...
fields: {
title: { type: 'string', required: true },
url_path: {
type: 'string',
resolve: (doc) => doc._raw.flattenedPath.replace(/pages\/?/, ''),
},
},
}))
```
To do this and still support current use cases, it'd be beneficial to not just pass the processed doc object, but also input data. (See #76 for an example use case.) IOW the shape of the `doc` passed to the `resolve` function might include the following properties:
- `_raw` would still be there as it is today
- `frontmatter` would contain the raw frontmatter content
- `body` (configurable) would contain the processed body
コントリビューションガイド
調査の方向性
まず `fields` と `computedFields` の現在の定義と処理を確認し、次に #76 で参照されているユースケースを読みます。フィールド定義で計算値に `resolve` を使用でき、現在のユースケースを維持しながら、`_raw`、生の `frontmatter`、および設定可能な処理済み `body` データを公開できれば完了です。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- typescript
- 領域
- tooling
- issue の種類
- 機能追加
- 難易度
- 5/5
- 見積もり時間
- 1週間以上
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 30/100