Upgrade Guide (v0.x -> v1.0)
ContentKit v1.0 führt eine neue, flexiblere Konfigurations-API ein. Während das alte Format vorerst weiterhin unterstützt wird, empfehlen wir dringend ein Upgrade auf das neue Format, um von verbesserter Typsicherheit und Developer Experience zu profitieren.
Migrationsschritte
1. Imports aktualisieren
Ersetze den alten ContentKitConfig Typ-Import durch die neuen Helper-Funktionen.
Alt:
import type { ContentKitConfig } from "contentkit/types";
const config: ContentKitConfig = {
/* ... */
};
export default config;Neu:
import { defineConfig, defineCollection, fields } from "contentkit";
// ... Collection Definitionen
export default defineConfig({
collections: [
/* ... */
],
});2. Collections definieren
Statt eines einzelnen documentTypes Arrays, definiere jede Collection einzeln mit defineCollection.
Alt:
documentTypes: [
{
name: "Post",
filePathPattern: "posts/**/*.md",
fields: {
/* ... */
},
},
];Neu:
const posts = defineCollection({
name: "Post",
directory: "./content/posts", // Basisverzeichnis für diese Collection
include: "**/*.md", // Glob Pattern relativ zum Verzeichnis
schema: {
/* ... */
},
});3. Feld-Definitionen aktualisieren
Verwende den fields Helper um dein Schema zu definieren. Dies bietet bessere Typ-Inferenz und Autocomplete.
Alt:
fields: {
title: { type: "string", required: true },
tags: { type: "array", items: { type: "string" } },
author: {
type: "object",
required: true,
fields: {
name: { type: "string", required: true }
}
}
}Neu:
schema: {
title: fields.string(),
tags: fields.array(fields.string()).optional(), // oder fields.list(...)
author: fields.object({
name: fields.string(),
}),
}Hinweis: Felder sind standardmäßig erforderlich (required). Verwende .optional(), um sie optional zu machen.
4. Computed Fields aktualisieren
Computed Fields werden nun mit der .resolve() Methode auf einer Feld-Definition definiert.
Alt:
computedFields: {
slug: {
type: "string",
resolve: (doc) => doc.title.toLowerCase().replace(/\s+/g, "-"),
},
}Neu:
computedFields: {
slug: fields.string().resolve((doc) => doc.title.toLowerCase().replace(/\s+/g, "-")),
}5. Globale Optionen entfernen
outputFormat und generateTypes werden nun automatisch anhand deiner package.json und tsconfig.json erkannt. Du kannst sie aus deiner Config entfernen, es sei denn, du musst die Standards überschreiben.
Alt:
export default {
contentDirPath: "content", // Jetzt pro Collection via `directory`
outputFormat: "esm", // Automatisch erkannt
generateTypes: true, // Automatisch erkannt
// ...
};Neu:
export default defineConfig({
collections: [posts],
});Vollständiges Beispiel
Vorher:
import type { ContentKitConfig } from "contentkit/types";
const config: ContentKitConfig = {
contentDirPath: "content",
outputFormat: "esm",
generateTypes: true,
documentTypes: [
{
name: "Post",
filePathPattern: "posts/**/*.md",
fields: {
title: { type: "string", required: true },
date: { type: "date", required: true },
},
computedFields: {
slug: {
type: "string",
resolve: (doc) => doc._raw.sourceFileName.replace(/\.md$/, ""),
},
},
},
],
};
export default config;Nachher:
import { defineConfig, defineCollection, fields } from "contentkit";
const posts = defineCollection({
name: "Post",
directory: "./content/posts",
include: "**/*.md",
schema: {
title: fields.string(),
date: fields.date(),
},
computedFields: {
slug: fields
.string()
.resolve((doc) => doc._raw.sourceFileName.replace(/\.md$/, "")),
},
});
export default defineConfig({
collections: [posts],
});