Content schema
The schema is the one description of a site’s content. The CMS builds the editing form from it and checks every save against it, and the site gets the types of its content: ContentOf<typeof schema>. The order of fields in the schema is the order of fields in the form.
import { defineSchema, text, type ContentOf } from "@seamlet/astro/schema";
export const schema = defineSchema({ title: text({ label: "Заголовок" }),});
export type Content = ContentOf<typeof schema>;Every field has a label — its name in the editor. The CMS’s interface is in Russian, so write it in Russian, the way the site’s owner will understand it.
Fields
Section titled “Fields”| Field | Value | Empty |
|---|---|---|
text({ label, multiline?, maxLength? }) |
a string | "" |
richText({ label, inline?, maxLength? }) |
paragraphs and lists with bold, italic and links (below) | [] |
number({ label, min?, max? }) |
a number | null |
date({ label }) |
a date "2026-10-24" |
null |
time({ label }) |
a time "09:30", from 00:00 to 23:59 |
null |
slug({ label }) |
the address of a record’s page: latte in /menu/latte (pages of records) |
"" |
image({ label }) |
{ src, alt, focus? } |
null |
file({ label }) |
a PDF document: { src, name } |
null |
link({ label }) |
{ text, href } |
null |
url({ label }) |
a web address without a text: a booking widget, a map | null |
toggle({ label }) |
true or false |
false |
choice({ label, options }) |
the value of one option |
null |
choices({ label, options }) |
the values of any number of options |
[] |
words({ label }) |
a list of words the owner types: notes of a taste, kinds of wood (below) | [] |
reference({ label, collection }) |
the id of a record of a collection |
null |
references({ label, collection }) |
the ids of any number of records |
[] |
group({ label, fields }) |
an object with the group’s fields | each field empty |
collection({ label, item, itemTitle? }) |
an array of records with the same fields | [] |
How to show a value to a visitor — a number with spaces, a date in words, a button or a text — is up to the site.
text — text
Section titled “text — text”text({ label: "Подзаголовок", multiline: true, maxLength: 200 });multiline — a text of several lines. maxLength — no longer than that many characters as a person sees them (an emoji is one).
richText — formatted text
Section titled “richText — formatted text”A text in which the owner makes words bold or italic and adds links and lists. The value is data, not HTML: paragraphs { kind: "paragraph", spans } and lists { kind: "list", items } of pieces { text, bold?, italic?, href? }. inline keeps the text one paragraph without lists — for an element of one line.
It is rendered by the package’s component, which puts out paragraphs and lists (with inline, only the words) and never raw HTML. Style its elements from around it:
---import RichText from "@seamlet/astro/components/RichText.astro";---
<div class="about" {...edit("about")}> <RichText value={content.about} /></div><p {...edit("note")}> <RichText value={content.note} inline /></p><style> .about :global(a) { color: inherit; }</style>A text with a link in the middle of a sentence is one richText field, not a text cut around the link. plainTextOf gives the words without formatting — for a page title or a description.
Which texts are formatted
Section titled “Which texts are formatted”The owner meets one rule: a paragraph can be formatted, everything else is typed as it is.
richText— prose: a lead, the description of a dish or an event, an “about us” text, a paragraph of terms. Every such text has the same set: bold, italic, link, and a list in a text of several paragraphs.text— headings, names of records, the words of buttons and links, an address, a phone, short labels. A link cannot go inside a button, the site makes a call link from a phone number, and an accent in a heading belongs to the site’s design, not to the owner.
Every mark must be visible on the page. If a font has no italic or the needed bold, and the browser may not fake them (font-synthesis: none), the owner presses «К» (italic) and sees nothing. Give <em> and <strong> a visible style: the italic of another font of the site, a colour, a loaded weight. Do not hide marks in separate fields: the same behaviour everywhere is clearer to the owner than a set of buttons that differs for every text.
file — document
Section titled “file — document”file({ label: "Прайс-лист" });The owner uploads a PDF — a price list, a banquet menu, a contract — and writes the words of the link. src is the address of the file in the CMS (/media/<site>/<file>.pdf), name the words of the link. It needs @seamlet/astro 1.4 or newer. A static build puts the files the pages link to next to them, as it does with uploaded photos:
{content.priceList && ( <a href={safeHref(content.priceList.src)} download> {content.priceList.name} </a>)}image — photo
Section titled “image — photo”image({ label: "Фото первого экрана" });src is the address of a photo uploaded to the CMS (/media/<site>/<file>.webp), of a photo from the site’s own files (/menu/01.jpg) or any other address. alt is what is in the photo, for those who cannot see it. The CMS turns uploaded photos upright, shrinks them to 2560 px on the longest side, saves them as WebP and removes metadata (where a phone photo was taken).
focus is the point that must stay in view when the site crops the photo; the owner sets it. imagePosition turns it into object-position (without a point, the middle):
<img src={photo.src} alt={photo.alt} style={`object-fit: cover; object-position: ${imagePosition(photo)}`}/>The site turns a photo from its own files into an image itself at build time. For the CMS’s editor to show such a photo in its field too, give defineSeamletSite a photos function that finds the image by its address:
const MENU_FILES = import.meta.glob<{ default: ImageMetadata }>( "./assets/menu/*.jpg", { eager: true },);
export default defineSeamletSite({ schema, initialContent, pages: { "/": { title: "Главная", component: HomePage } }, photos: (src) => MENU_FILES[src.replace("/menu/", "./assets/menu/")]?.default,});link and url — links
Section titled “link and url — links”link is a link with a text: to a page of the site (/menu), another site (https://…), a phone (tel:) or an email (mailto:). Anything else, for example javascript:, the CMS does not save. url is only a web address, without a text: for example, an online booking widget or a map.
choice and choices — options
Section titled “choice and choices — options”Options are { value, label }: the site reads value, the editor shows label, so a label can change without touching the site. The content gets the exact type:
const level = choice({ label: "Нагрузка", options: [ { value: "soft", label: "Мягко" }, { value: "active", label: "Активно" }, ],});// ContentOf gives "soft" | "active" | nullchoices keeps the chosen values in the order of the schema’s options.
words — a list of words
Section titled “words — a list of words”For a few words the site shows one by one, as tags or a list: «Бергамот, персик, мёд». The owner adds, removes and reorders words one at a time and does not think about commas. The value is an array of strings, without spaces at the ends, without empty ones and without repeats:
const notes = words({ label: "Ноты во вкусе" });// ContentOf gives readonly string[]<ul {...edit("roast", "notes")}> {roast.notes.map((note) => ( <li>{note}</li> ))}</ul>If a field used to be a text “with commas”, you can make it words at once: the CMS reads the saved text as words. It works the other way too: a text gets the words with commas. In the table and in an Excel file the list is one cell, the words between commas. The CMS reads a words field from version 2.8.0 of the package.
toggle — switch
Section titled “toggle — switch”To let the owner hide a record without removing it, give the record a switch and do not show hidden records:
item: { name: text({ label: "Название" }), isHidden: toggle({ label: "Скрыть с сайта" }),}// content.practices.filter((practice) => !practice.isHidden)group — group
Section titled “group — group”group({ label: "Контакты", fields: { address: text({ label: "Адрес" }), phone: link({ label: "Телефон" }), },});Fields that are shown and kept together, for example the first screen of a page.
collection — collection
Section titled “collection — collection”collection({ label: "Меню", itemTitle: "name", item: { name: text({ label: "Название" }), price: number({ label: "Цена, ₽", min: 0 }), },});A list of records of one kind: dishes of a menu, reviews, staff. The owner adds, removes and reorders records right on the page, and every record may have a page of its own. itemTitle is the field that names a record in the editor («Эспрессо» instead of «Запись 1», “Record 1”): a text field or a link (by its text).
Every record has its own id, which does not change when records are reordered, so a record cannot have a field named id. The CMS gives an id to records without one, so the initial content may leave it out — unless something refers to those records.
reference and references — references to records
Section titled “reference and references — references to records”A record picks another record by its id: the teacher of a class is picked from the teachers, and a teacher’s new name shows in all of their classes at once. collection is where the collection is: its name or a path through groups.
const schema = defineSchema({ teachers: collection({ label: "Преподаватели", itemTitle: "name", item: { name: text({ label: "Имя" }) }, }), practices: collection({ label: "Практики", itemTitle: "name", item: { name: text({ label: "Название" }), teacher: reference({ label: "Ведёт", collection: "teachers" }), }, }),});// findRecord(content.teachers, practice.teacher)?.nameA reference to a removed record is kept with the issue missing-record: the CMS does not save the content until the owner picks another record or clears the field.
Presets
Section titled “Presets”Sets of fields almost every site has, edited the same way everywhere. They are plain groups and collections, and the site shows them as it likes. Each takes { label } to name it otherwise.
seoFields()—title,descriptionandimageof a page for search engines and links shared in messengers;contactsFields()—phone(a link),address,map(an address) andmessengers(links);openingHoursField()— rows ofdays(WEEKDAYS),opensandclosestimes and anote;shownUntilField()— the last day a record or a block is shown on the site (adatefield, may be empty); more below;productFields()— the fields of a product of a catalog with its characteristics as pairs of a name and a value (not a preset group, but the fields of a record: pages of records and the catalog).
Where a page holds its title and description for search engines is named by the page’s searchTexts in defineSeamletSite ("seo.home"). The editor then puts those fields first and shows how the page looks in search results.
Shown until
Section titled “Shown until”An offer that ends on Sunday must leave the site on Monday by itself, without a publication. Give the record or the block a shownUntilField() field, and check it on the page by the day in the business’s time zone:
---import { calendarDayIn, editable, isShownOn } from "@seamlet/astro/schema";import type { SiteContent } from "../schema";
const { promo } = Astro.props.content;const edit = editable<SiteContent>();const today = calendarDayIn("Europe/Moscow", new Date());---
{isShownOn(promo.shownUntil, today) && ( <p {...edit("promo", "text")}>{promo.text}</p>)}isShownOn shows the record up to and including the last day, and always when the field is empty. calendarDayIn takes the day where the business is, not where the server is: in Kirov the offer ends at midnight Kirov time. A site that renders pages on request checks the date on every visit. A static site checks it only at its next build.
Initial content
Section titled “Initial content”Until the site is published, it shows its initial content. ContentOf checks it at build time:
import type { Content } from "./schema";
export const initialContent: Content = { title: "Моя кофейня",};Changing the schema
Section titled “Changing the schema”A new schema reaches the CMS with the site’s deployment: the CMS takes it from the site itself every time it opens the site in the editor.
- A new field in content saved before gets its value from the site’s initial content (inside groups too), and an empty value if it is not there. So a site that makes the text of its pages editable keeps its words. Records of collections stay as they were saved.
- Renaming a field is, for the CMS, removing the old one and adding a new one: the saved value of the old field leaves the form, and the new one takes its value from the initial content.
- A
textthat becomesrichTextkeeps its words, and arichTextthat becomestextdoes too, without formatting (from@seamlet/astro0.12.1 and a CMS on it).