5. A page per session and speaker

Map one route to a whole list and get a page for every session and speaker, with Markdown rendered by Markdig.

On this page
csharp
app.MapStatic<SessionPage>("/sessions/{Slug}", (ISiteData data) => data.Sessions);
app.MapStatic<SpeakerPage>("/speakers/{Id}", (ISiteData data) => data.Speakers);

Two lines make thirteen pages: eight sessions and five speakers. Bevel renders one page for each item in the list.

  1. Map the routes

    Add using Bevel.Conference.Data; to the top of Program.cs, because the handlers ask for ISiteData. Then add these routes after the schedule route:

    samples/Bevel.Conference/Program.cscsharp
    // One page per item: {Slug} is filled from each session's Slug property.
    app.MapStatic<SessionPage>("/sessions/{Slug}", (ISiteData data) => data.Sessions);
    samples/Bevel.Conference/Program.cscsharp
    app.MapStatic<SpeakerPage>("/speakers/{Id}", (ISiteData data) => data.Speakers);

    {Slug} is filled from each session's Slug property. {Id} is filled from each speaker's Id. The page receives the item as a typed parameter.

  2. Render the Markdown

    Bevel gives you the raw Markdown. You pick the renderer. Add Markdig:

    bash
    dotnet add package Markdig

    Create Components/Markdown.razor:

    samples/Bevel.Conference/Components/Markdown.razorrazor
    @using Markdig
    
    @((MarkupString)Html)
    
    @code {
      [Parameter] [EditorRequired] public string Source { get; set; } = "";
    
      private string Html => Markdig.Markdown.ToHtml(Source);
    }
  3. Write the session page

    Create Pages/SessionPage.razor. This is the whole file. The @code block at the bottom is how the page receives its session:

    samples/Bevel.Conference/Pages/SessionPage.razorrazor
    @layout MainLayout
    @inject ISiteData Data
    @inject ISiteLinks Links
    
    <SectionContent SectionName="head">
      <title>@Session.Title — @Data.Site.Title</title>
      <meta name="description" content="@Session.Summary"/>
    </SectionContent>
    
    <p class="crumb"><a href="@(Links.To<SchedulePage>())">← Schedule</a></p>
    <p class="when">
      @Session.Start.ToString("dddd, MMMM d") ·
      @Session.Start.ToString("HH:mm") – @Session.End.ToString("HH:mm") ·
      @Session.Room
    </p>
    <h1>@Session.Title</h1>
    <p class="by">
      with <a href="@Links.To(Session.Speaker)">@Session.Speaker.Name</a>, @Session.Speaker.Role
    </p>
    
    <Markdown Source="@Session.RawMarkdown"/>
    
    @code {
      [Parameter] [EditorRequired] public Session Session { get; set; } = default!;
    }
  4. Write the speaker page

    Create Pages/SpeakerPage.razor the same way. It receives a Speaker instead:

    samples/Bevel.Conference/Pages/SpeakerPage.razorrazor
    @layout MainLayout
    @inject ISiteData Data
    @inject ISiteLinks Links
    
    <SectionContent SectionName="head">
      <title>@Speaker.Name — @Data.Site.Title</title>
      <meta name="description" content="@Speaker.Bio"/>
    </SectionContent>
    
    <p class="crumb"><a href="@(Links.To<HomePage>())">← Home</a></p>
    <h1>@Speaker.Name</h1>
    <p class="by">@Speaker.Role · @@@Speaker.Handle</p>
    <p class="lead">@Speaker.Bio</p>
    
    <h2>Sessions</h2>
    @foreach (var session in Data.Sessions.Where(s => s.Speaker.Id == Speaker.Id))
    {
      <SessionCard Session="session"/>
    }
    
    @code {
      [Parameter] [EditorRequired] public Speaker Speaker { get; set; } = default!;
    }

    It lists the sessions that belong to this speaker with a plain LINQ Where.

  5. Now you can link to them. Replace Components/SessionCard.razor with this version. It adds @inject ISiteLinks Links and two links:

    samples/Bevel.Conference/Components/SessionCard.razorrazor
    @inject ISiteLinks Links
    
    <article class="session">
      <p class="when">@Session.Start.ToString("HH:mm") – @Session.End.ToString("HH:mm") · @Session.Room</p>
      <h3><a href="@Links.To(Session)">@Session.Title</a></h3>
      <p class="by">
        <a href="@Links.To(Session.Speaker)">@Session.Speaker.Name</a>
      </p>
      <p>@Session.Summary</p>
    </article>
    
    @code {
      [Parameter] [EditorRequired] public Session Session { get; set; } = default!;
    }

    In Pages/HomePage.razor, make each speaker's name a link:

    razor
    <a href="@Links.To(speaker)"><strong>@speaker.Name</strong></a>

    Add @inject ISiteLinks Links to the top of that file too.

Run it

Open the schedule and click a session title. You should land on a session page with the time, the room, the speaker's name and the talk text. Click the speaker.

A session page for From Forty Minutes to Forty Seconds with a time and room line, a title, the speaker Priya Raman and two paragraphs of text.
Step 5: a session page. The text is Markdown rendered by Markdig.
A speaker page for Priya Raman with her role, handle, bio and a list of her sessions.
Step 5: a speaker page that lists the speaker's sessions.

Try it: add a new session file, save, and open /sessions/your-file-name. It exists.

Next: 6. Calendar feed.