Documentation

Publication

Give a VitNode Content Engine content type drafts and a Publish button with the publication option, so nothing reaches readers until an editor publishes it.

publication gives every record two states: Draft and Published. Drafts stay private, and only staff with the publish permission can make a record public. Turn it on before anything else on the public side, because the public API only ever returns published records.

Turn it on

Add one line to the definition:

plugins/example/src/content/article.ts
export const articleContentType = defineContentType({
  id: "example.article",
  tableName: "example_articles",
  fields: {
    title: field.text({ required: true }),
    slug: field.slug({ source: "title" }),
  },
  publication: true, 
});

This adds a status column (draft or published), a publishedAt date, a can_publish permission and Publish and Unpublish buttons in the AdminCP.

Name the permission

plugins/example/src/locales/en.json
{
  "@vitnode/example:article:can_publish": "Publish and unpublish articles"
}

Migrate

Run this from the workspace root while pnpm dev is running:

Migrate the database
bun run db:migrate

Existing rows become drafts. pnpm dev picks up the new option by itself.

What a reader sees

The record isThe public API answers
A draft404, like a slug that never existed
Published with a future publishedAt404 until that moment
PublishedThe record

The API never says whether a draft exists. To publish later on a schedule, or to share a draft with someone before it goes live, add editorial.

Check the result

Open AdminCP → Example → Articles. New articles show a Draft badge. Click the paper plane Publish button at the end of a row:

Articles list with Hello Content Engine marked Draft and the Publish tooltip over the paper plane button in its row

Confirm with Yes, publish it, and the badge turns into Published. The create dialog also gets Save as draft and Publish buttons, and bulk actions publish many rows at once.

Publish Article dialog asking to publish Hello Content Engine, with Cancel and Yes, publish it buttons