Guides
Site configuration
The two files that tell the editor about your site, one for the browser and one for the server.
The editor reads your site through two files. By default they are src/visual-editor.config.ts and src/visual-editor.server.ts; other paths can be set with visualEditor({ config, server }).
The browser config
src/visual-editor.config.ts is bundled into /admin, so it must be browser-safe: no node: imports, no content collections.
import { defineVisualEditorConfig } from '@vamped/editor/blocks';
import { registry } from './lib/blocks';
export default defineVisualEditorConfig({
registry,
icons: { hero: 'M3 5h18v14H3Z M7 10h7 M7 13h10' },
locales: { all: ['en'], default: 'en', names: { en: 'English' } },
homeSlug: 'home',
pagePath: (slug) => (slug === 'home' ? '/' : `/${slug}/`),
pageFile: (slug) => `src/content/pages/${slug}.yml`,
entryId: (slug) => slug,
parseEntryId: (id) => ({ slug: id, locale: 'en' }),
});
| Member | What it is for |
|---|---|
registry |
Your blocks, from createRegistry. |
icons |
Icons by name, as SVG path data on a 24×24 grid, drawn with a stroke. Blocks and select options name them. |
locales |
Every language code, the default one, and each one’s name in its own language. |
homeSlug |
The slug of the home page, whose URL is the language’s root. |
pagePath(slug, locale?) |
A page’s URL path: /, /about/, /de/about/. |
pageFile(slug, locale?) |
A page’s file, relative to the project root. |
entryId(slug, locale?) |
A page’s content entry ID: about, de/about. |
parseEntryId(id) |
An entry ID split into { slug, locale }. |
The server config
src/visual-editor.server.ts is loaded only by the preview service. It default-exports a VisualEditorServer:
import { readFile } from 'node:fs/promises';
import { parse } from 'yaml';
import type { VisualEditorServer } from '@vamped/editor/blocks';
import Layout from './components/Layout.astro';
import PageRenderer from './components/PageRenderer.astro';
import { registry } from './lib/blocks';
import { siteSettingsSchema } from './lib/site';
const readYaml = async (path: string) => {
try {
return parse(await readFile(new URL(path, import.meta.url), 'utf8'));
} catch {
return undefined;
}
};
const server: VisualEditorServer = {
async getPage(slug) {
if (!/^[a-z0-9-]+$/.test(slug)) return undefined;
const parsed = registry.pageSchema.safeParse(await readYaml(`./content/pages/${slug}.yml`));
return parsed.success ? parsed.data : undefined;
},
getSiteSettings: async () => siteSettingsSchema.parse(await readYaml('./content/settings/site.yml')),
siteSettingsSchema,
translationsOf: async (slug) => ({ en: slug === 'home' ? '/' : `/${slug}/` }),
Layout,
PageRenderer,
};
export default server;
| Member | What it is for |
|---|---|
getPage(slug, locale?) |
The saved page, for the preview’s first frame. Check the slug before using it in a path. |
getSiteSettings(locale?) |
Navigation, footer and anything else your layout needs. |
siteSettingsSchema |
The schema of those settings, used to check unsaved ones from the CMS. |
translationsOf(slug) |
The page’s URL in every language it exists in. |
Layout |
The layout the preview renders pages in. It gets title, description, settings, locale, translations, and with the design editor on, design. |
PageRenderer |
The component that renders sections, as on your published pages. |
Use the same Layout and PageRenderer for your published pages. That is what makes the preview trustworthy: it is your site, not a look-alike.