Create a category taxonomy for content
Use a reusable categories collection and a has-many relationship from content entries that need tagging.
This generated recipe is review-ready source material. Use it from the runtime where it appears in the sidebar and search results.
Use a reusable categories collection and a has-many relationship from content entries that need tagging.
Use this when
- add categories to posts
- model reusable taxonomy entries
- tag content with multiple categories
- build filtered content listings
Dyrected concepts
relationship, hasMany, urlPattern
Additional packages: No additional packages.
Decisions and cautions
Use this recipe only when its runtime matches the project you are documenting or building. Cloud recipes must stay inside the managed content backend boundary. Self-hosted recipes may use the server runtime, database, hooks, and infrastructure you control.
Complete recipe
This is the canonical source compiled and behavior-tested by @dyrected/knowledge.
import { defineCollection, defineRelationshipField, defineTextField } from "@dyrected/core";
export const Categories = defineCollection({
slug: "categories",
admin: { useAsTitle: "title", urlPattern: "/categories/{slug}" },
fields: [
defineTextField({ name: "title", label: "Title", required: true }),
defineTextField({ name: "slug", label: "Slug", required: true, unique: true }),
],
});
export const Posts = defineCollection({
slug: "posts",
admin: { useAsTitle: "title", urlPattern: "/blog/{slug}" },
fields: [
defineTextField({ name: "title", label: "Title", required: true }),
defineTextField({ name: "slug", label: "Slug", required: true, unique: true }),
defineRelationshipField({
name: "categories",
label: "Categories",
relationTo: "categories",
hasMany: true,
}),
],
});