Drafts and removing items

Drop drafts or any other item from a dataset with a record processor that returns ProcessResult.Remove.

On this page
csharp
[Process<DropDrafts>]
public sealed record BlogPost(string Slug, string Title, bool Draft = false);

public sealed class DropDrafts(IHostEnvironment env) : IProcessor<BlogPost>
{
    public ProcessResult<BlogPost> Process(BlogPost post)
        => post.Draft && !env.IsDevelopment() ? ProcessResult.Remove : post;
}

Return ProcessResult.Remove from a record processor to drop an item. Both return post with { ... }; and => cond ? ProcessResult.Remove : post; compile.

Bevel has no built-in draft handling. Give the record a Draft member (draft: true in the front matter binds to it) and drop drafts yourself. The example keeps drafts only in Development.

!IsDevelopment() rather than IsProduction() keeps drafts out of Staging and preview builds too. To never publish drafts, skip the environment check and always return ProcessResult.Remove for them.

What removal does

  • A removed item is gone. Later record processors do not run for it, and it is absent from the data, groups and [Unique] checks.
  • A reference to a removed item fails the build and names the processor that removed it.
  • Removal is not allowed in a single-object dataset (BEVEL093), and member processors cannot remove.
  • A result that holds null is BEVEL085, like returning null.