contentlayerdev / contentlayerdev/contentlayer

Combine `fields` and `computedFields`

未关闭
#91 2 条评论 5 个 reaction 已指派 0 人 在 GitHub 查看
feature pkg/source-files
主要语言
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

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。