2. Speakers from YAML

Declare a Speakers dataset from one YAML file and list the speakers on the home page.

On this page
samples/Bevel.Conference/Data/Speakers/Speaker.cscsharp
namespace Bevel.Conference.Data;

[DataSource("Speakers", "./speakers.yaml", OrderBy = "Name")]
public sealed record Speaker(
    [Unique(IgnoreCase = true)] string Id,
    string Name,
    string Role,
    string Bio,
    string Handle);

A conference needs people. Five speakers fit in one YAML file, so you load them as one dataset.

  1. Describe a speaker

    Create Data/Speakers/Speaker.cs with the file above. Three things happen here:

    • [DataSource("Speakers", "./speakers.yaml")] names the dataset and its file.
    • OrderBy = "Name" sorts the list.
    • [Unique(IgnoreCase = true)] on Id fails the build if two speakers share an id. You will use that id for URLs and references.
  2. Write the people

    Create Data/Speakers/speakers.yaml. A YAML list becomes a list of records. Keys match the record's members, ignoring case:

    samples/Bevel.Conference/Data/Speakers/speakers.yamlyaml
    - id: ada
      name: Ada Okafor
      role: Principal Engineer, Northwind
      bio: Ada has shipped Razor to production since the first preview. She believes every site should start as a folder of text files.
      handle: adaships
    - id: mateo
      name: Mateo Ribeiro
      role: Developer Advocate
      bio: Mateo teaches .NET on stage and on stream. His demos usually work on the first try, and he is very proud of that.
      handle: mateocodes
    - id: priya
      name: Priya Raman
      role: Staff Engineer, Contoso
      bio: Priya turns slow builds into fast ones. She once cut a deploy from forty minutes to forty seconds.
      handle: priyaraman
    - id: jonas
      name: Jonas Lindqvist
      role: Indie Developer
      bio: Jonas builds tiny tools for people who run events. His calendar feeds are used by thousands of attendees.
      handle: jonasbuilds
    - id: sam
      name: Sam Carter
      role: Design Engineer
      bio: Sam makes plain CSS look expensive. No framework, no build step, lots of tasteful borders.
      handle: samcarter
  3. List them on the home page

    Add this under the hero section in Pages/HomePage.razor:

    razor
    <h2>Speakers</h2>
    <ul class="speakers">
      @foreach (var speaker in Data.Speakers)
      {
        <li>
          <strong>@speaker.Name</strong>
          <span>@speaker.Role</span>
        </li>
      }
    </ul>

Run it

If dotnet watch is still running, save and refresh. If not, start it again with dotnet watch. You should see five speaker cards under the hero, sorted by name: Ada, Jonas, Mateo, Priya, Sam.

The home page with a Speakers heading and five cards: Ada Okafor, Jonas Lindqvist, Mateo Ribeiro, Priya Raman and Sam Carter, each with a role.
Step 2: five speakers, loaded from speakers.yaml.

Try it: add a sixth speaker to the YAML and save. A card appears. Now copy an id so two speakers share it. The build fails and the error points at the duplicate. Remove the copy.

Next: 3. Sessions in Markdown.