contentlayerdev / contentlayerdev/contentlayer

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

Đang mở
#86 3 bình luận 1 reaction 0 người được giao Xem trên GitHub
feature
Ngôn ngữ chính
TypeScript
Star
3.5k
Fork
192
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Mô tả

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"
},
// ...
}
```

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Đánh giá

Issue này chưa được đánh giá.

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.