contentlayerdev / contentlayerdev/contentlayer

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

Offen
#86 3 Kommentare 1 Reaktion 0 zugewiesene Personen Auf GitHub ansehen
feature
Vorherrschende Sprache
TypeScript
Sterne
3.5k
Forks
192
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

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

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit der Dokumenttyp-Konfiguration und den beiden Beispiel-Inhaltsdateien im Issue und reproduziere die aktuelle Referenzausgabe. Verfolge, wie die `category`-Referenz aufgelöst wird, und ermittle, wie sich eine optionale Embedding-Einstellung darauf auswirken sollte; abgeschlossen ist die Aufgabe, wenn die Ausgabe das Kategorieobjekt mit seinem Titel enthalten kann und das bestehende Referenzverhalten erhalten bleibt, wenn Embedding nicht aktiviert ist.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
typescript
Bereich
content
Issue-Typ
Feature
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
42/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.