Start here
Getting started
Install the package, describe one block, and edit your first page in the visual editor.
This guide adds vamped editor to an existing Astro site. At the end you will have a hero block, a home page made of blocks, and the visual editor at /admin.
1. Install
npm install @vamped/editor@next @sveltia/cms astro zod
Then add the integration:
// astro.config.mjs
import { defineConfig } from 'astro/config';
import visualEditor from '@vamped/editor';
export default defineConfig({
integrations: [visualEditor()],
});
The integration builds and serves /admin with Sveltia CMS and the editor, and adds the preview routes under /__visual/ while astro dev runs. Don’t keep an admin/index.html of your own in public/.
2. Describe a block
// src/lib/blocks.ts
import { z } from 'zod';
import { createRegistry, defineBlock } from '@vamped/editor/blocks';
export const hero = defineBlock({
type: 'hero',
label: 'Hero',
description: 'Large introduction with a heading and text.',
icon: 'hero',
category: 'Hero',
schema: z.object({ heading: z.string().min(1, 'Add a heading'), text: z.string() }),
defaults: { heading: 'A clear headline', text: '' },
fields: [
{ name: 'heading', label: 'Heading', type: 'text', inline: true },
{ name: 'text', label: 'Text', type: 'textarea', inline: true },
],
});
export const registry = createRegistry([hero]);
3. Write its component
Mark each editable element with data-ve-field, but only while the preview renders the page:
---
// src/components/Hero.astro
const { heading, text } = Astro.props;
const field = (name: string) => (Astro.locals.visualEditing ? { 'data-ve-field': name } : {});
---
<section class="hero">
<h1 {...field('heading')}>{heading}</h1>
{text && <p {...field('text')}>{text}</p>}
</section>
4. Render a page’s blocks
A page renderer turns sections into components. In the preview it wraps each block in an element with its ID, type and label:
---
// src/components/PageRenderer.astro
import { registry } from '../lib/blocks';
import Hero from './Hero.astro';
const components: Record<string, any> = { hero: Hero };
const { sections = [] } = Astro.props;
const editing = Astro.locals.visualEditing === true;
---
{sections.map((section) => {
const Component = components[section.type];
return editing ? (
<div data-ve-block={section.id} data-ve-type={section.type} data-ve-label={registry.get(section.type)?.label}>
<Component {...section.props} />
</div>
) : <Component {...section.props} />;
})}
Use the same renderer in your pages (src/pages/index.astro and friends), so the preview and the published site are built from the same code.
5. Tell the editor about your site
Two files, described in detail in Site configuration:
src/visual-editor.config.ts: the registry, icons, languages and where pages live. It runs in the browser.src/visual-editor.server.ts: how to read a saved page, and the layout and renderer the preview uses. It runs only on the server.
6. Configure Sveltia
In public/admin/config.yml, add a collection named pages:
backend:
name: github
repo: your-name/your-site
branch: main
media_folder: public/images
public_folder: /images
collections:
- name: pages
label: Pages
folder: src/content/pages
extension: yml
format: page-yaml
create: true
identifier_field: title
slug: '{{slug}}'
editor:
preview: false
fields:
- { name: title, label: Page title, widget: page-field }
- { name: description, label: SEO description, widget: page-field, multiline: true, required: false }
- { name: sections, label: Page content, widget: visual-blocks }
See Sveltia CMS setup for what each line does.
7. Edit
Run npm run dev, open http://localhost:4321/admin/ and sign in with your backend. On localhost, Sveltia also offers Work with Local Repository (Chrome or Edge), which edits your project folder directly. Open Pages, create a page, choose Add the first block and pick Hero. Click the heading in the preview and type.