How Bevel works

How files under Data/ become typed C# data, how pages read it, and how an export writes static HTML.

On this page

Files go in. Typed C# comes out. Your pages render it live, or Bevel writes it to disk as HTML.

Diagram: files under Data/ go through a build-time data step into a typed ISiteData. Razor pages mapped with MapStatic read it and render live while developing or as static files on export.

The four ideas

  • A dataset is one named collection of content, such as Posts or Authors. You declare it with a C# record and a [DataSource] attribute.
  • The data step runs during dotnet build. It reads every dataset, checks it, and generates ISiteData. That interface has one typed property per dataset. The MSBuild target behind it is called BevelPrebuild, so you also see "prebuild" in file and property names.
  • Your pages read ISiteData. You route them with MapStatic.
  • An export renders every mapped page and writes the result to disk as static files.

What happens inside the data step

The data step does more than read files. It follows this order:

Diagram: the data step reads files, binds them to records, runs processors that can remove items, then applies OrderBy, [Unique], references and groups, and writes a snapshot.

Read the full list in Processors. The short version: Bevel binds each file to your record, runs your processors, then sorts, checks uniqueness, resolves references and builds groups. A mistake fails the build with an error that names the file.

The data graph

Bevel builds a graph of every dataset, with edges from [DependsOn] and [Reference]. It validates the graph, then runs datasets in layers. The LoadOrder setting (the [LoadOrder] attribute on a custom loader, or the LoadOrder property of [DataSource]) only breaks ties inside a layer. The build prints the result:

text
data graph: [Authors, Site] -> [Posts] -> [Posts.Tags] -> [Metrics]

Each dataset is stored as a UTF-8 JSON file embedded in the assembly as a resource (Bevel.Data.<Namespace>.<Dataset>.<hash>.json, written to obj/.../Bevel/data/). Bevel reads it once, on first use, through a source-generated System.Text.Json context. The generated C# stays small however much content you have. Bevel serializes every dataset and reads it back during the build to make sure nothing is lost.

Live, exported or served

While you develop, the app renders pages live. When you are ready, dotnet run -- --bevel-build writes plain HTML. If your ASP.NET Core app serves the site, Bevel can answer from the exported files in production.

Diagram: when an ASP.NET Core app serves the site, Development renders pages live. In other environments Bevel serves the exported file when it matches its recorded hash, and renders live with a warning when the file is missing or changed. On a static host, the host serves the files and handles fallbacks.