Skip to content
qino

Since 0.1.0

defineTree

Define hierarchical, ordered content backed by nested folders.

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(),
    markdown: 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)>;
  views?: (view: ViewHelper) => Record<string, View> & { default: View };
}): Tree;

Parameters

NameTypeRequiredDefaultDescription
directory`/${string}`yesDirectory under contentFolder. Walked recursively. Owned exclusively by this tree
extension".md" | ".mdx" | ".markdown" | ".json"yesOnly files with this extension are nodes
schemaStandard Schema object validatoryesSynchronous. May not declare _meta
titleFieldkey of schema outputyesField whose string value titles each node. Non-string keys are a type error
orderFileNamestringno"_order.json"Per-folder ordering file
relationsRecord<path, primitive | () => primitive>no{}Same grammar as collections
views(view) => { default: View; [name]: View }noHelper offers resolveRelations and augment only. filter and sort are rejected

Returns

A Tree with five 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.

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

See also

In this section