Skip to content

Connecting a site

An Astro site connects with the package @seamlet/astro. It adds a preview for the editor, the bridge to it and serving of photos from the CMS. You name the site, describe its content and mark it in the markup.

In the folder of an Astro project:

Окно терминала
npx @seamlet/astro init --title "Моя кофейня" --token <token>
npx astro add @seamlet/astro node

<token> is your owner token: the CMS’s page «Подключить сайт» (Connect a site) shows it (a developer’s account). A site the CMS’s administrator connects needs no token. Instead of node you may take vercel or netlify — where to host the preview. An AI agent can do the same for you.

init creates seamlet.json, src/schema.ts (a schema with one text and the initial content), src/seamlet.ts and a component of the first page — only the files the project does not have yet. It takes the site’s id in the CMS from name in package.json (or from --id), the title from --title (without it, the id), the CMS https://cms.seamlet.ru (or --cms), and the token from --token. astro add installs the package and adds the integration and the @astrojs/node adapter. Below is what you get, step by step.

Окно терминала
npm install @seamlet/astro @astrojs/node

The preview is rendered on request, so the site needs an adapter, for example @astrojs/node, @astrojs/vercel or @astrojs/netlify. The site’s own pages may stay static.

seamlet.json
{
"id": "cafe",
"title": "Моя кофейня",
"cms": "https://cms.seamlet.ru",
"ownerToken": "<token>"
}
  • id — the site’s id in the CMS: lower-case Latin letters, digits and hyphens. The CMS keeps the site’s content under it (/sites/cafe), and the address of the preview the CMS builds is made from it. The id must be free: the CMS does not connect a taken one — give the site another.
  • title — what the site is called in the CMS.
  • cms — the address of the CMS: the site takes its published content from there, and only its editor may frame the preview. The environment variable CMS_ORIGIN replaces it at build time — for example, for a CMS on your own computer.
  • ownerToken — the owner token from the CMS: it tells the CMS that the person connecting the site is the one who deploys it. It is not a secret; it may stay in the repository. init --token writes it, and into an existing seamlet.json you add it by hand. A site the administrator connects needs no such field.

The file lives at the root of the repository: the CMS reads it from there when a site is connected from its repository. If the file is missing or a field is wrong, the build stops and says what to fix.

src/schema.ts
import {
collection,
defineSchema,
group,
image,
number,
text,
type ContentOf,
} from "@seamlet/astro/schema";
export const schema = defineSchema({
hero: group({
label: "Первый экран",
fields: {
title: text({ label: "Заголовок", maxLength: 60 }),
photo: image({ label: "Фото" }),
},
}),
menu: collection({
label: "Меню",
itemTitle: "name",
item: {
name: text({ label: "Название" }),
price: number({ label: "Цена, ₽", min: 0 }),
},
}),
});
export type Content = ContentOf<typeof schema>;

Every field kind and its options are in the reference.

src/seamlet.ts
import { defineSeamletSite } from "@seamlet/astro/site";
import HomePage from "./components/HomePage.astro";
import MenuPage from "./components/MenuPage.astro";
import { initialContent } from "./initial-content";
import { schema } from "./schema";
export default defineSeamletSite({
schema,
initialContent,
pages: {
"/": { title: "Главная", component: HomePage },
"/menu": { title: "Меню", component: MenuPage },
},
});
  • initialContent — what the site shows while nothing is published (initial content).
  • pages — the site’s pages by their addresses, the home page / first. Each has a title in the editor and a component that gets the content in its content prop. searchTexts (for example, "seo.home") names where the content holds the page’s title and description for search engines — a group of a title and a description text, as in seoFields().
  • photos — optional: how to find a photo from the site’s own files by its address, so the editor shows it in its field.

The CMS takes all of this from the site at /seamlet/site.json (the integration adds it), so neither connecting a site nor a new schema needs any change in the CMS.

astro.config.mjs
import node from "@astrojs/node";
import seamlet from "@seamlet/astro";
import { defineConfig } from "astro/config";
export default defineConfig({
adapter: node({ mode: "standalone" }),
integrations: [seamlet()],
});

The integration reads seamlet.json and src/seamlet.ts itself. Its options:

  • checks — what the build does with texts of the pages the editor cannot edit: "warn" lists them (the default), "strict" stops the build, "off" does not check them. More in checking the markup;
  • sitemap, robots, llms — files for search engines and AI assistants, all on. false turns a file off (search).

The site’s pages take the published content with loadPublishedContent():

src/pages/index.astro
---
import site from "../seamlet";
import HomePage from "../components/HomePage.astro";
const content = await site.loadPublishedContent();
---
<HomePage content={content} />

This serves one page. If there are several, like / and /menu above, or the records of a collection have pages of their own (products, dishes, articles), serve all pages from one route, src/pages/[...page].astro — see pages of records.

Every site on Seamlet names it once — at the bottom of the footer, next to the privacy policy: a small link «Сделано на Seamlet» (“Made with Seamlet”) to https://seamlet.ru/. Whoever looks for it finds it; it does not get in the way of others.

  • It is the code’s text, not the owner’s: mark it data-cms-fixed, or the strict check of the markup stops the build.
  • Colour — the muted text colour of the footer; size — one step smaller (0.8125rem); no underline. On hover and focus the link takes the colour of the footer’s main text and is underlined.
  • Font, spacing and colours — as in the rest of the site’s footer. Contrast at least 4.5:1, a touch target at least 44 px.
  • If the footer already names Seamlet in the code’s text («Демо-сайт, сделанный на Seamlet»), a second credit is not needed.
src/components/Footer.astro
<p class="footer-legal" data-cms-fixed>
<a href="/privacy">Политика конфиденциальности</a>
<a class="footer-made" href="https://seamlet.ru/">
Сделано на Seamlet
</a>
</p>
<style>
.footer-legal {
display: flex;
flex-wrap: wrap;
gap: 0 1.5rem;
}
.footer-legal a {
display: inline-flex;
align-items: center;
min-height: 44px;
}
.footer-made {
color: var(--footer-muted);
font-size: 0.8125rem;
text-decoration: none;
}
.footer-made:hover,
.footer-made:focus-visible {
color: var(--footer-text);
text-decoration: underline;
}
</style>

Next: mark in the markup which element shows which field, and connect the preview in the CMS.