Skip to content
Editlet

Quick start: Astro

Follow these steps to add Editlet to an Astro site (astro ^6 || ^7) and edit an entry in astro dev. Your entries become Astro content collections.

Install with your agent

Give your coding agent the prompt from Quick start: Next.js. The same skill sets up Astro.

Install by hand

  1. Install the package and link the agent skills:

    npm install editlet
    node node_modules/editlet/skills/editlet/scripts/link.mjs --hooks
  2. Add the integration. It adds the ?editlet loader to every page. astro dev serves the editor at /editlet/ and the dev file API at /__editlet, and astro build copies the editor into the output.

    // astro.config.mjs
    import editlet from 'editlet/astro';
    import { defineConfig } from 'astro/config';
    
    export default defineConfig({ integrations: [editlet()] });
  3. Create cms/schema.json and one entry, as in steps 5 and 6 of Quick start: Next.js.

  4. Create src/content.config.ts. It makes one Astro collection per schema collection.

    import { editletCollections } from 'editlet/astro/content';
    
    export const collections = editletCollections();
  5. Run npm run dev and open http://localhost:4321/?editlet. In dev, a save changes the local file.

To keep your own collections too, add each Editlet one with editletLoader, and give it no schema:

import { defineCollection } from 'astro:content';
import { editletLoader } from 'editlet/astro/content';

export const collections = {
  post: defineCollection({ loader: editletLoader('post') }),
  // your other collections
};

Show content on a page

---
import { getCollection, getEntries, getEntry, render } from 'astro:content';
import { Image } from 'astro:assets';

const home = await getEntry('home', 'index');        // a singleton: the id is 'index'
const posts = await getCollection('post');           // the id is the slug
const author = await getEntry(posts[0].data.author); // a reference → that entry
const related = await getEntries(posts[0].data.related ?? []); // a list of references; one call per level
const { Content } = await render(posts[0]);          // the Markdown body
---
{posts[0].data.cover && <Image src={posts[0].data.cover.src} alt={posts[0].data.cover.alt} />}
<Content />

Mark the element that shows an entry with data-editlet-entry="post/hello-world". The editor can then point at it, and you can select words in it and press Edit.

Tell the schema which page shows an entry: "url": "/posts/{slug}/" on the collection, matching your route src/pages/posts/[slug].astro and the trailing / of your links. The editor then shows the page's address in New entry and Details, and ⋯ → Open on the page goes there. Add "pluralLabel": "Posts" for the list heading. See Content model.

Options

editlet() takes schemaPath (default cms/schema.json, relative to the Astro root) and admin, the settings for the live site.

Limits

  • Astro base is not supported. The editor is always at /editlet/ and the dev API at /__editlet.
  • astro build leaves out draft: true entries, and a reference to a draft resolves to undefined.
  • A static site has no server, so the auth handler for GitHub sign-in runs elsewhere.

For agents: this page as Markdown · llms.txt