Skip to content

Since 0.1.0

defineItem

Define a single content file with its own role.

View Markdown
On this page

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()),
  }),
  relations: { "featured-posts[*]": postCollection },
});

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)>;
  media?: Record<StringPath, MediaRule>;
  markdown?: {
    stats?: boolean;
    toc?: boolean | { upTo?: "h1" | "h2" | "h3" | "h4" | "h5" | "h6"; slug?: (text: string) => string };
    media?: MediaRule | Array<MediaRule>;
  };
  views?: (view: ViewHelper) => Record<string, View> & { default: View };
  page?: `/${string}` | { path: `/${string}`; markdownComponents?: Record<string, PageMarkdownComponent<Entry>> };
  cloud?: { displayAs?: string; hiddenFields?: Array<OptionalField>; media?: { saveFileAs?: string } };
}): Item;

type MediaRule = { accepted: MimeType; maxSize: Size; parse?: (value: string, ctx: MediaParseContext) => string | undefined };

Parameters

There is no extension option and no slug.

Returns

An Item with three getters.

Getters

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.
  • "<id>" sets `cloud`, but initQino doesn't. Add `cloud` to initQino.
  • Item "<file>" declares a page, so initQino needs a siteUrl, such as "https://example.com".
  • Item "<file>": page "<path>" <what's wrong>., such as must start with "/". See Errors.

See also