Since 0.2.0
initQino
Initialize the instance that all definitions hang off.
Initializes a qino instance bound to a content folder and a media folder. Every collection, tree, and item is defined through the returned instance.
import { initQino } from "@qino/cms";
const qino = initQino({
contentFolder: "src/content",
mediaFolder: "public",
cli: {
check: { localAssetReferences: { exclude: ["/og/**"] } },
},
cloud: {
publish: { mode: "open_pull_request", reviewBeforePublish: true },
},
});
Signature
function initQino(config: {
readonly contentFolder: string;
readonly mediaFolder: string;
readonly siteUrl?: string;
readonly cli?: {
readonly check?: {
readonly localAssetReferences?:
boolean | { readonly exclude?: ReadonlyArray<string> };
};
readonly build?: {
readonly types?: boolean;
readonly llmsTxt?:
boolean | { readonly template?: string; readonly sections?: boolean };
};
};
readonly cloud?: {
readonly publish:
| {
readonly mode: "open_pull_request";
readonly reviewBeforePublish:
boolean | { readonly bypassIfAdmin?: boolean };
readonly branchPrefix?: string;
}
| {
readonly mode: "commit_to_default_branch";
readonly reviewBeforePublish:
boolean | { readonly bypassIfAdmin?: boolean };
};
};
readonly incrementalEntries?: boolean;
}): {
defineCollection: typeof defineCollection;
defineTree: typeof defineTree;
defineItem: typeof defineItem;
};
Parameters
The config type is not exported; pass an object literal.
Returns
An instance with three methods:
The methods are closures, so destructuring them is fine:
export const { defineCollection, defineTree, defineItem } = initQino({
contentFolder: "src/content",
mediaFolder: "public",
});
Each instance carries a unique identity. Primitives from one instance cannot be related to primitives from another, and qino lint rejects a project that mixes instances.
Incremental entries
A getEntries call, or a getPaginatedEntries call on a view that filters or sorts, builds every entry of the collection: its images, its relations, and the view. Parsed files are cached, but on a large collection the rest still takes seconds per call under next dev, which makes every promise slower. incrementalEntries keeps each view's entries between calls, and builds again only the ones whose files changed:
export default initQino({
contentFolder: "src/content",
mediaFolder: "public",
incrementalEntries: process.env.NODE_ENV == "development",
});
- Each entry is kept with every file it was built from: its own file, its images, and each relation target it resolved, with the target's images, down to the resolve depth.
- Each call checks those files, with one sync stat per file, and builds again only the entries whose files changed. An edit shows up on the next call.
- A file read within 2 seconds of an edit is read again on every call until it's older, because some file systems record modification times only to the second or two.
augment,filter, andsortstill run on every call, over every entry, so afilterthat reads the clock or anaugmentthat reads other data stays fresh. A syncaugmentadds little. An async one adds a promise per entry.- Entries are kept per collection instance and view, so the first call for a view on an instance still builds every entry.
- Other reads build their entries on every call, as without the option:
getEntry,getPaginatedEntrieson a view that neither filters nor sorts, and every tree and item getter.
With the option on:
- A reused entry skips its relation and media
parsecallbacks, as a cached file skips its schema transforms, so they don't run on every call. Read other data inaugmentinstead. - A lazy relation target,
() => collection, must return the same collection every time. - Entries that reference one target can hold different objects for it. Group them by the target's
_meta.filePathor slug, not by object. - Nested objects are shared between calls made one after another, not only between concurrent ones. Treat entries as read-only.
It's meant for dev. A production build prerenders its pages, and a content change ships in a new deploy. The checks block the event loop while they run, which is quick on a local disk but slower on a network drive or a Docker bind mount.
Throws
siteUrl "<siteUrl>" must be an http(s) origin, such as "https://example.com".A path after the host is rejected, but a trailing/is allowed and dropped.
Folder existence is checked by the CLI, not at creation.
CLI expectations
The CLI loads qino/index.ts and requires the instance to be its default export. See Project structure.