---
title: "defineItem"
description: "Define a single content file with its own role."
canonical: "https://www.qino.works/docs/api/item"
---

# defineItem

> Define a single content file with its own role.

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

```ts title="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

```ts title="@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

| Name        | Type                                                  | Required | Default | Description                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| ----------- | ----------------------------------------------------- | -------- | ------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `file`      | `` `/${string}<ext>` ``                               | yes      |         | Path under `contentFolder`, with extension. The extension is inferred from it                                                                                                                                                                                                                                                                                                                                                                                                                              |
| `schema`    | Standard Schema object validator                      | yes      |         | Synchronous. May not declare `_meta`, nor `markdown`/`_stats`/`_toc` for Markdown                                                                                                                                                                                                                                                                                                                                                                                                                          |
| `relations` | `Record<path, primitive \| () => primitive>`          | no       | `{}`    | Same grammar as collections                                                                                                                                                                                                                                                                                                                                                                                                                                                                                |
| `media`     | `Record<path, MediaRule>`                             | no       | `{}`    | Media fields, keyed by path to a string field, with the one MIME type each accepts and its max size. Image fields are read as `QinoImage`, and `parse` reads a value first. See [Media](https://www.qino.works/docs/concepts/media)                                                                                                                                                                                                                                                                                              |
| `markdown`  | `{ stats?; toc?; media? }`                            | no       | `{}`    | Configures the body. Markdown and MDX only. `stats` adds `_stats`, its word and character counts. See [MarkdownStats](https://www.qino.works/docs/api/types/markdown-stats). `toc` adds `_toc`, its headings with their anchor ids: `true` lists every level, `upTo` stops at one, and `slug` sets how ids are made. See [MarkdownToc](https://www.qino.works/docs/api/types/markdown-toc). `media` lists the rules body images must match, each read with its own `parse`. See [Body images](https://www.qino.works/docs/concepts/media#body-images)                        |
| `views`     | `(view) => { default: View; [name]: View }`           | no       |         | Helper offers `resolveDepth` and `augment` only                                                                                                                                                                                                                                                                                                                                                                                                                                                            |
| `page`      | `` `/${string}` `` \| `{ path; markdownComponents? }` | no       |         | The item's page, such as `"/about"`, for page Markdown, its Markdown URL and `llms.txt`'s `## Pages` section. Takes no token, and follows the path rules of [collections' `pages`](https://www.qino.works/docs/api/collection#pages). Requires `siteUrl` on `initQino`. The object form, `{ path: "/about", markdownComponents }`, also takes functions, by component name, whose output replaces an MDX component in page Markdown. Markdown and MDX only. See [PageMarkdownComponent](https://www.qino.works/docs/api/types/page-markdown-component) |
| `cloud`     | `{ displayAs?; hiddenFields?; media? }`               | no       |         | Cloud UI name, hidden fields, and where uploads are saved. Requires `cloud` on `initQino`. See [Cloud](https://www.qino.works/docs/guide/cloud#primitives)                                                                                                                                                                                                                                                                                                                                                                       |

There is no `extension` option and no slug.

## Returns

An `Item` with three getters.

### Getters

- [`getEntry(options?)`](https://www.qino.works/docs/api/item/get-entry)
- [`getPageMarkdown()`](https://www.qino.works/docs/api/item/get-page-markdown)
- [`getMarkdownUrl()`](https://www.qino.works/docs/api/item/get-markdown-url)

## Throws

At definition time, the shared view errors listed on [defineCollection](https://www.qino.works/docs/api/collection), 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](https://www.qino.works/docs/api/errors#pages).

## See also

- [Items](https://www.qino.works/docs/concepts/items)
- [Agent-ready content](https://www.qino.works/docs/guide/agent-ready-content)
