← @mortar-kit/core

CollectionDefinitioninterface

import { CollectionDefinition } from '@mortar-kit/core'

interface CollectionDefinition<F extends Fields>

What a developer passes to defineCollection.

Properties

name: string

Stable identifier, also the storage folder. Lowercase, e.g. posts or case-studies.

label?: string

Plural name for the admin panel ("Posts"). Defaults to name.

fields: F

The fields every document has, built with fields.*.

body?: boolean

Whether documents also have brick entries (a body made of bricks). Default false.

title?: keyof F & string

A text field shown as the document's title in lists and pickers. Defaults to the first text field; without one, the slug is shown.

sort?: SortOrder<keyof F & string>

The default list order. Defaults to the title field (or the slug), ascending. With orderable, lists follow the manual order instead and this orders only documents that have no place in it yet.

orderable?: boolean

Whether editors put the documents in order by hand (drag or move up/down in the admin). Lists then follow that order unless they pass a sort, and new documents go to the end. The order is kept in each document's position, which createContent manages. Default false.

reservedSlugs?: readonly string[]

Slugs documents may not use, e.g. the app's own route segments next to /:slug (admin). Segments other collections' urls start with are refused anyway (see url).

url?: string

Where a document is on the site: a path with one :slug segment, e.g. /posts/:slug or /:slug. One pattern drives the app's route (the same syntax as @solidjs/router), links (urlOf), the admin's preview links, and the sitemap; next to /posts/:slug, a /:slug collection can't use the slug posts. Mortar doesn't route: the app still declares its routes, from this.

home?: string

With url: the slug of the document at the pattern's prefix instead, e.g. home at / for /:slug.

canWrite?: (write: CollectionWrite<F>) => boolean | Promise<boolean>

Who may change this collection's documents, checked by createContentServer after its own canWrite (both must allow): false refuses the write with a 403. Gets the user, the document as stored and, for a save, the one sent, so a rule can be scoped to the document (only the projects someone belongs to).