Most plugin tutorials print "hello" to a log. This one builds something a real site would install: a rule that stops anyone from publishing a post without a proper excerpt, the short summary that search results and social cards show. It is about thirty lines of code, and emDash's own test tools can prove it works against the real publishing code before it goes near a site.

We built it on emDash 1.4 with the official plugin tools, ran the tests, and looked at the three ways to install it. One of those needs a paid Cloudflare plan, which is worth knowing before you start.

Sandboxed or native

emDash has two kinds of plugins:

  • Sandboxed plugins run in a separate, locked-down runtime. They can only use the emDash features their manifest declares, and an administrator approves those permissions at install. They can be published to emDash's plugin registry and installed from the admin.
  • Native plugins run inside the site with full access. They can add React screens to the admin, custom rich text blocks and page fragments, but they install like any code dependency and need a redeploy.

emDash recommends sandboxed unless you need one of the native-only features. This site's own two plugins are native: one defines custom rich text blocks, and the other ships a React admin screen for the newsletter. A publishing rule needs neither, so ours is sandboxed.

Step 1: scaffold it

The plugin command line tool creates a working project:

bash
				
					pnpm dlx @emdash-cms/plugin-cli init excerpt-guardcd excerpt-guardpnpm installpnpm run test
				
			

Run interactively, it asks for three things the registry will need later: a publisher, an author and a security contact. Run non-interactively, it needs them as flags, and the publisher must be an Atmosphere (Bluesky-style) handle that resolves to an identity, or that identity's DID directly. The scaffold includes a sample route, a passing test, and emDash's plugin-writing instructions for AI coding assistants.

Step 2: declare what it may do

The manifest, emdash-plugin.jsonc, is the plugin's identity and its trust contract. Ours asks for one capability and declares two settings for administrators:

jsonc
				
					{	"slug": "excerpt-guard",	"publisher": "did:plc:…",	"license": "MIT",	"author": { "name": "Your name" },	"security": { "url": "https://example.com/security" }, 	// The only authority this plugin needs: a say in whether content is published.	"capabilities": ["hooks.content-policy:register"],	"allowedHosts": [],	"storage": {}, 	"admin": {		"settingsSchema": {			"minExcerptLength": {				"label": "Minimum excerpt length",				"type": "number",				"default": 80,				"min": 0,				"max": 500			},			"collections": {				"label": "Collections to check",				"description": "Comma-separated collection slugs.",				"type": "string",				"default": "posts"			}		}	}}
				
			

The capability matters. It lets the plugin refuse a publish, but it doesn't let the plugin read other content, write anything or publish on its own. An administrator installing it sees exactly that in the consent dialog, and changing the list in a later version means asking for consent again.

Step 3: write the rule

The code lives in src/plugin.ts. emDash calls the publish-policy hooks before an entry is published or scheduled. Returning nothing allows the action; returning a cancellation with a reason refuses it, and the editor sees the reason.

ts
				
					import type { PluginContext, SandboxedPlugin } from "emdash/plugin"; const DEFAULT_MIN_LENGTH = 80;const DEFAULT_COLLECTIONS = "posts"; interface PolicyEvent {	collection: string;	content: { data?: unknown };} // Returns a rejection when the entry's excerpt is missing or too short.async function checkExcerpt(event: PolicyEvent, ctx: PluginContext) {	const listed = String((await ctx.settings.get("collections")) ?? "")		.split(",")		.map((slug) => slug.trim())		.filter(Boolean);	// An empty list falls back to the default, so clearing the field can't switch the rule off unnoticed.	const collections = listed.length > 0 ? listed : [DEFAULT_COLLECTIONS];	if (!collections.includes(event.collection)) return; 	const min = Number((await ctx.settings.get("minExcerptLength")) ?? DEFAULT_MIN_LENGTH);	const data = (event.content.data ?? {}) as Record<string, unknown>;	const excerpt = typeof data.excerpt === "string" ? data.excerpt.trim() : "";	if (excerpt.length >= min) return; 	return {		cancel: true as const,		reason: `Write an excerpt of at least ${min} characters first. This one has ${excerpt.length}.`,	};} const plugin: SandboxedPlugin = {	hooks: {		"content:beforePublish": async (event, ctx) => checkExcerpt(event, ctx),		"content:beforeSchedule": async (event, ctx) => checkExcerpt(event, ctx),	},}; export default plugin;
				
			

Two details from emDash's hook documentation shaped it. The publish event carries the draft that is about to go live, so the rule checks what readers will see. And a scheduled entry runs the publish check again when it comes due, so checking at scheduling time as well catches the problem while someone is still at the keyboard.

Step 4: prove it works

emDash's test package offers two hosts. The fast one loads the plugin through the same sandbox the site uses and calls a hook directly. The runtime one goes further: it builds a small emDash site in memory, so a test can create a post and try to publish it through emDash's real publish action.

ts
				
					it("blocks publishing until the excerpt is long enough or the setting changes", async () => {	const host = await createPluginRuntimeTestHost();	await host.fixtures.collection({		slug: "posts",		label: "Posts",		fields: [			{ slug: "title", label: "Title", type: "string" },			{ slug: "excerpt", label: "Excerpt", type: "text" },		],	});	const entry = await host.fixtures.content("posts", {		slug: "draft-post",		data: { title: "Draft post", excerpt: "Short." },	}); 	const refused = await host.actions.content.publish("posts", entry.id);	if (refused.success) throw new Error("publish should have been refused");	expect(refused.error.code).toBe("PUBLISH_REJECTED"); 	await host.actions.plugin.updateSettings({ minExcerptLength: 5 });	expect((await host.actions.content.publish("posts", entry.id)).success).toBe(true);	await host.dispose();});
				
			

Our five tests passed: a short excerpt refused, a long one allowed, other collections ignored, the real publish refused with the plugin's own message until the setting changed, and the rule still applied after the collections setting was cleared. That last one caught a real gap. emDash checks number settings against the manifest before saving them, so a minimum that isn't a number from 0 to 500 never reaches the plugin. An empty text setting is saved as it is, so the first version quietly stopped checking anything, and the plugin now falls back to posts. The test command also validates the manifest first.

The plugin and its tests were written with an AI coding agent, Claude Code. We relied on the tests, not the agent: each one runs the real hook or the real publish action, and they ship with the plugin, so whoever maintains it later can run them again.

1permission the plugin asks for: a say in whether content is published
557 bytesfor the built plugin; the release bundle is 1.5 KB
5tests, including a real publish through emDash's own publish action

pnpm run build produces the files a site loads, and pnpm run bundle the tarball a registry release contains. We stopped there. Publishing to the registry needs the publisher's Atmosphere account and goes through emDash's release verification, so we didn't publish a test plugin under a placeholder identity.

Step 5: install it, and the catch

There are three ways to run a sandboxed plugin on a site:

RouteWhat it needsIsolation
Install from the registry in the adminA published release, and a sandbox runner on the siteFull: separate runtime, declared permissions, resource limits
List it under sandboxed plugins in the site configA sandbox runner and a redeployFull
List it under ordinary plugins in the site configA redeploy onlyNone: runs inside the site, permissions checked but not enforced by a boundary

The sandbox runner is the catch. On Cloudflare, emDash runs each sandboxed plugin as its own Worker through a feature called Worker Loader, which needs the Workers Paid plan and a binding the site templates leave switched off. On Node.js, the runner is the open-source workerd runtime started alongside the site, at no extra cost.

Without a runner, sandboxed plugins simply don't load, and registry installs fail with an error saying the sandbox isn't available. The rest of the site carries on.

This site runs on the free plan and doesn't enable the binding, which is one reason our own plugins are native. For a small rule like this one, written by you and doing nothing but refuse a publish, listing it as an ordinary plugin is a reasonable choice. For anything from someone else, or anything that touches content and the network, the sandbox is the point.

The sandbox protects the site from the plugin, not the rule from being wrong. It stops a plugin from reaching anything it wasn't granted, but only the tests show that the rule does what you meant.

Before you ship your first emDash plugin0/6 done

Should it go in the registry?

Not necessarily. A house rule like this one encodes one site's editorial standards. It's exactly the kind of small feature a developer can build with an agent, test, and keep in the site's own code. It belongs in the registry only if it's general enough for other sites and you're prepared to maintain it as emDash changes.

Check first, too. On 10 November 2026, the registry already listed five plugins that check or block posts before publishing, including two different ones both called seo-guard, and one, Preflight, that already blocks posts with a missing excerpt. Improving or building on one of those may help more people than adding a sixth. Our piece on what should earn a place in the emDash registry sets out the trade-off.

Where a first plugin pays off

  • Running an emDash site yourself. House rules like this one, such as excerpts, alt text or a category on every post, are the easiest plugins to write and the ones that save the most editing mistakes.
  • Evaluating emDash. The permission model and the test tools are a real step up from plugin systems where every plugin can do anything. Budget for the Workers Paid plan if you want third-party plugins to run sandboxed on Cloudflare.
  • Running an agency. Package each client's editorial rules as a small plugin with tests, rather than as custom code in the site. The same plugin then works on the next client's site.