contentlayerdev / contentlayerdev/contentlayer

Fields of type `reference` should be able to embed their data

未关闭
#86 3 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看
feature
主要语言
TypeScript
星标
3.5k
派生
192
PR 合并指标
30 天内没有已合并 PR

描述

Given the following config:

```js
const Category = defineDocumentType(() => ({
name: 'Category',
filePathPattern: 'categories/*.md',
bodyType: 'none',
fields: {
title: { type: 'string', required: true },
},
}))

const Doc = defineDocumentType(() => ({
name: 'Doc',
filePathPattern: '**/*.mdx',
bodyType: 'mdx',
fields: {
title: { type: 'string', required: true },
category: { type: 'reference', of: Category }
},
}))

export default makeSource({
contentDirPath: 'content',
documentTypes: [Doc, Category],
})
```

And the following content files:

`content/categories/a.md`

```yaml
---
title: My First Category
---
```

`content/docs/index.mdx`

```yaml
---
title: Home Page
category: categories/a.md
---
```

The output document would have the following:

```json
{
"title": "Home Page",
"category": "categories/a.md",
// ...
}
```

It would be nice to (optionally) embed the category data directly in the output document. Otherwise, I have to defer that logic to my application. Being that it's data manipulation, it seems right that Contentlayer would handle this.

I'd rather see the output like this:

```json
{
"title": "Home Page",
"category": {
"title": "My First Category"
},
// ...
}
```

贡献指南

打开贡献指南

评估

这个 Issue 还没有评估数据。

把新 issue 发到你的邮箱

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