contentlayerdev / contentlayerdev/contentlayer

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

Abierto
#86 3 comentarios 1 reacción 0 asignados Ver en GitHub
feature
Lenguaje dominante
TypeScript
Estrellas
3.5k
Forks
192
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

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

Guía de contribución

Abrir la guía de contribución

Línea de trabajo

Comienza con la configuración del tipo de documento y los dos archivos de contenido de ejemplo del issue, reproduciendo la salida de referencia actual. Sigue cómo se resuelve la referencia `category` y determina cómo debería afectarle una configuración opcional de embedding; el trabajo estará terminado cuando la salida pueda contener el objeto de categoría con su título, preservando el comportamiento de referencia existente cuando el embedding no esté habilitado.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
typescript
Área
content
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
42/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.