Draft Preview

In LeadCMS, a draft is any piece of content that either has no publishedAt date or has a publishedAt date in the future. Drafts allow you to work on pages or posts without immediately publishing them to your production site. This article explains how drafts are handled by the LeadCMS SDK and how to preview them without accidental publication.

How drafts work

Draft content behaves differently depending on the environment:

  • Production builds: When you build your static site for production (next build, astro build, etc.), the SDK excludes drafts by default. Only content with a past publishedAt date is included in the static output. This ensures that unpublished content does not appear on your live site.
  • Preview mode: When running a preview server (see Preview Setup), the SDK can return draft content for direct slug requests. In SDK v3+, this behavior is environment-based (NODE_ENV and LEADCMS_PREVIEW) instead of using legacy includeDrafts parameters.

Recommended approach

To avoid confusion and duplicate entries in your lists, we recommend the following best practices:

  1. Exclude drafts from collections by default. When displaying lists of articles, projects or any enumerable content, filter out items where publishedAt is null or in the future. This prevents unfinished work from appearing alongside published posts.
  2. Use direct links to preview drafts. Editors can preview an unpublished page by navigating directly to its slug. For example, /blog/my-unpublished-post/ will render the draft on the preview server (but not on production). This requires that your page component always fetches the content by slug and handles drafts transparently.
  3. Enable preview mode with environment variables. Use NODE_ENV=development (default preview behavior) or LEADCMS_PREVIEW=true. To force published-only behavior, set LEADCMS_PREVIEW=false.

Keeping drafts out of lists by default maintains a clean editing experience and prevents duplicate entries.

Handling drafts in different scenarios

  • Page components: For single pages, use getCMSContentBySlugForLocale(slug, locale, userUid?). The SDK applies draft visibility rules based on preview mode.
  • Collections: For lists, use getAllContentSlugsForLocale(locale, contentTypes, userUid?) and then fetch each item by slug. Sorting by publishedAt remains the same; items without a publishedAt date should appear at the end (or be excluded).

Draft scheduling

You can schedule content by setting publishedAt to a future date. During production builds the content will only appear once the current date exceeds the scheduled time. On preview servers, you can still open the page directly by slug to see how it will look.

Summary

Drafts are essential for a content‑first workflow, allowing you to iterate without affecting your live site. In modern SDK versions, preview behavior is environment-driven and draft flags are no longer passed as separate boolean parameters.

Next steps

With draft handling implemented, explore live preview functionality or prepare for deployment: