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.
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.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
| Name | Type | Required | Default | Description |
|---|---|---|---|---|
directory | `/${string}` | yes | Directory under contentFolder. Walked recursively. Owned exclusively by this tree | |
extension | ".md" | ".mdx" | ".markdown" | ".json" | yes | Only files with this extension are nodes | |
schema | Standard Schema object validator | yes | Synchronous. May not declare _meta | |
titleField | key of schema output | yes | Field whose string value titles each node. Non-string keys are a type error | |
orderFileName | string | no | "_order.json" | Per-folder ordering file |
relations | Record<path, primitive | () => primitive> | no | {} | Same grammar as collections |
views | (view) => { default: View; [name]: View } | no | Helper 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.