Skip to content

Since 0.1.0

defineTree

Define hierarchical, ordered content backed by nested folders.

View Markdown
On this page

Defines a tree: a nested directory where every node is a file and sections are a file plus a same-named folder. Returns getters for structure, content, and navigation.

qino/trees/docs.ts
import { z } from "zod";

import qino from "../";

export const docsTree = qino.defineTree({
  directory: "docs",
  extension: ".md",
  titleField: "title",
  schema: z.object({
    title: z.string(),
  }),
});

Signature

@qino/cms
qino.defineTree(params: {
  directory: `/${string}`;
  extension: ".md" | ".mdx" | ".markdown" | ".json";
  schema: StandardSchemaV1<unknown, Record<string, unknown>>;
  titleField: StringKeyOfSchemaOutput;
  orderFileName?: string;
  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 };
  pages?: { index: `/${string}`; entry: `/${string}{slug}${string}`; title: string; llmsFull?: boolean; markdownComponents?: Record<string, PageMarkdownComponent<Entry>> };
  cloud?: { displayAs?: string; displayEntryAs?: `${string}{${RequiredField}}${string}`; saveEntryAs?: `${string}{${RequiredField}}${string}`; searchableBy?: Array<Field>; hiddenFields?: Array<OptionalField>; media?: { saveFileAs?: string } };
}): Tree;

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

Parameters

Returns

A Tree with nine getters.

Getters

Throws

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

  • tree views do not support filter or sort.
  • tree view "<name>" does not support filter or sort.
  • "<id>" sets `cloud`, but initQino doesn't. Add `cloud` to initQino.
  • The pages errors listed on defineCollection, naming Tree "<directory>".

Layout errors surface when a getter walks the tree. See getTree.

See also