Datasets
Declare a dataset with DataSource, choose a path and an order, and read it from your pages as typed C# data.
On this page
[DataSource("Authors", "./authors.json")]
public sealed record Author(string Id, string Name);
You put [DataSource] on a record. The first argument is the dataset name. The second is a path. Bevel loads the file and adds data.Authors to ISiteData.
Pick a format with the extension
The file extension picks the format: .json, .yaml/.yml, .xml, or .md/.markdown. A folder holds Markdown documents.
- A JSON or YAML array becomes
IReadOnlyList<T>. An object becomesT. - XML elements bind constructor parameters by attribute or child-element name, ignoring case.
- Add
OrderBy = "Date desc, Title"to sort any list dataset. An unknown member fails the build.
[DataSource("Site", "./site.yaml", LoadOrder = 1)]
public sealed record SiteConfig(string Title, string Description);
[DataSource("Authors", "./authors.json")]
public sealed record Author(string Id, string Name);
[DataSource("Navigation", "./navigation.xml", Element = "link")]
public sealed record NavItem(string Label = "", string Href = "/", string Location = "header");
Keep each dataset next to its data
- Data/
- Site/
- SiteConfig.cs
- site.yaml
- Authors/
- Author.cs
- authors.json
- Navigation/
- NavItem.cs
- navigation.xml
- Posts/
- BlogPost.cs
- getting-started.md
Paths
./xand../xresolve relative to the.csfile that declares the attribute.- Anything else is relative to the project root, or absolute.
- The last segment may be a wildcard (
./*.md). It matches files in that directory only, sorted by path. No matches gives an empty list. A missing directory is an error. - A bare
**segment matches folders at any depth. See Nested folders. SourcePathis the path relative to the wildcard root, with/separators. For./*.mdit is the file name.
How Bevel orders datasets
Bevel builds a graph of every dataset, with edges from [DependsOn] and [Reference]. It validates the graph, then runs datasets in layers. Two settings only break ties inside a layer, and lower numbers run first: the LoadOrder property of [DataSource] (as on SiteConfig above), and the [LoadOrder] attribute on a custom IBevelDataLoader class. Neither can make a dataset run before one it depends on. The build prints the result:
data graph: [Authors, Site] -> [Posts] -> [Posts.Tags] -> [Metrics]