Skip to content
qino

Since 0.1.0

defineItem

Define a single content file with its own role.

Defines an item: one file at a fixed path. Returns a single getter.

qino/items/home.ts
import { z } from "zod";

import qino from "../";
import { postCollection } from "../collections/posts";

export const homeItem = qino.defineItem({
  file: "/pages/home.md",
  schema: z.object({
    title: z.string(),
    "featured-posts": z.array(z.string()),
    markdown: z.string(),
  }),
  relations: { "featured-posts[*]": postCollection },
  views: (view) => ({
    default: view({ resolveRelations: true }),
  }),
});

Signature

@qino/cms
qino.defineItem(params: {
  file: `/${string}.md` | `/${string}.mdx` | `/${string}.markdown` | `/${string}.json`;
  schema: StandardSchemaV1<unknown, Record<string, unknown>>;
  relations?: Record<RelationPath, Primitive | (() => Primitive)>;
  views?: (view: ViewHelper) => Record<string, View> & { default: View };
}): Item;

Parameters

NameTypeRequiredDefaultDescription
file`/${string}<ext>`yesPath under contentFolder, with extension. The extension is inferred from it
schemaStandard Schema object validatoryesSynchronous. May not declare _meta
relationsRecord<path, primitive | () => primitive>no{}Same grammar as collections
views(view) => { default: View; [name]: View }noHelper offers resolveRelations and augment only

There is no extension option and no slug.

Returns

An Item with one getter: getEntry(options?).

Throws

At definition time, the shared view errors listed on defineCollection, plus:

  • extractExtension: file "<file>" must end with one of .md, .mdx, .markdown, .json.
  • item views do not support filter or sort.
  • item view "<name>" does not support filter or sort.

See also

In this section