6. Calendar feed
Map a route that is not a page and write a calendar.ics file attendees can add to their calendar app.
On this page
// A route that is not a page. The file name decides the exported file: calendar.ics.
app.MapStatic("/calendar.ics", (ISiteData data, ISiteLinks links) =>
BevelResults.Text(CalendarFeed.Build(data.Site, data.Sessions, links), "text/calendar; charset=utf-8"));
Not every file is a web page. Calendar apps read .ics files. Bevel can export those too: MapStatic takes a handler that returns text, XML or JSON, and the file name in the route names the exported file.
Map the route
Add the route above to
Program.cs.BevelResults.Textreturns plain text with the content type you choose. The handler asks forISiteDataandISiteLinks, and Bevel supplies both.Write the feed
An iCalendar file is plain text with a few strict rules. Create
CalendarFeed.csin the project root. This is the whole file, so you can copy it as it is:samples/Bevel.Conference/CalendarFeed.cscsharp using System.Text; using Bevel.Conference.Data; namespace Bevel.Conference; /// <summary>Builds an iCalendar (.ics) feed. The format is plain text with a few strict rules.</summary> public static class CalendarFeed { // iCalendar lines end in CRLF, not just LF. private const string NewLine = "\r\n"; public static string Build(SiteConfig site, IEnumerable<Session> sessions, ISiteLinks links) { var zone = TimeZoneInfo.FindSystemTimeZoneById(site.TimeZone); var lines = new List<string> { "BEGIN:VCALENDAR", "VERSION:2.0", "PRODID:-//Bevel Conf//Schedule//EN", "CALSCALE:GREGORIAN", "X-WR-CALNAME:" + Escape(site.Title) }; foreach (var session in sessions) { // Sessions are written in local conference time. Calendars want UTC. var start = TimeZoneInfo.ConvertTimeToUtc(session.Start, zone); var end = TimeZoneInfo.ConvertTimeToUtc(session.End, zone); lines.Add("BEGIN:VEVENT"); lines.Add($"UID:{session.Slug}@bevel-conf.example"); // DTSTAMP says when the event was written. A fixed value keeps the file identical between builds. lines.Add("DTSTAMP:20261129T000000Z"); lines.Add($"DTSTART:{start:yyyyMMdd'T'HHmmss'Z'}"); lines.Add($"DTEND:{end:yyyyMMdd'T'HHmmss'Z'}"); lines.Add("SUMMARY:" + Escape(session.Title)); lines.Add("DESCRIPTION:" + Escape($"{session.Summary} Speaker: {session.Speaker.Name}.")); lines.Add("LOCATION:" + Escape($"{session.Room}, {site.City}")); // links.To(...) respects PathBase. AbsoluteUrl adds the SiteUrl origin, so the URL is right wherever the site is hosted. lines.Add("URL:" + links.AbsoluteUrl(links.To(session))); lines.Add("END:VEVENT"); } lines.Add("END:VCALENDAR"); return string.Concat(lines.Select(line => Fold(line) + NewLine)); } /// <summary>Escapes the characters that have a meaning inside an iCalendar text value.</summary> private static string Escape(string text) => text .Replace("\\", "\\\\") .Replace(";", "\\;") .Replace(",", "\\,") .Replace("\r\n", "\\n") .Replace("\n", "\\n"); /// <summary> /// Lines may be at most 75 bytes. A longer line continues on the next line, which starts with one space. /// Counting bytes (not characters) keeps multi-byte letters like "ã" whole. /// </summary> private static string Fold(string line) { var result = new StringBuilder(); var bytesInLine = 0; foreach (var rune in line.EnumerateRunes()) { var size = rune.Utf8SequenceLength; if (bytesInLine + size > 75) { result.Append(NewLine).Append(' '); bytesInLine = 1; // the leading space counts } result.Append(rune.ToString()); bytesInLine += size; } return result.ToString(); } }Here is what the parts do:
Buildwrites oneVEVENTper session. Session times are in local conference time, so it converts them to UTC with theTimeZonesetting fromsite.yaml.DTSTAMPis a fixed value, so the file is identical between builds.links.AbsoluteUrl(links.To(session))adds the site origin to a link that already has your path base, so theURLis right wherever you host. It needsoptions.SiteUrl, which the sample sets inProgram.csfrom theBEVEL_SITE_URLenvironment variable. Step 7 shows it.Escapehandles the characters that mean something in iCalendar: backslash, semicolon, comma and line breaks.Foldsplits lines longer than 75 bytes. It counts bytes, not characters, so a letter like "ã" stays whole. BothFoldandBuilduse theNewLineconstant, because iCalendar lines end in\r\n.
Add the using
The route in
Program.cscallsCalendarFeed. YourProgram.csneedsusing Bevel.Conference;at the top, next to the otherusinglines.Program.csshould now start like this:Program.cscsharp using Bevel.Conference; using Bevel.Conference.Data; using Bevel.Conference.Pages;Link to it
Add a link in
Components/MainLayout.razor, inside the<nav>.Links.Routelinks to a route that has no page behind it:razor <a href="@Links.Route("/calendar.ics")">Calendar</a>Add two buttons to the hero section of
Pages/HomePage.razor, under the tagline:razor <p> <a class="button" href="@(Links.To<SchedulePage>())">See the schedule</a> <a class="button ghost" href="@Links.Route("/calendar.ics")">Add to your calendar</a> </p>
Run it
Open /calendar.ics. You should see a text file that starts with BEGIN:VCALENDAR and has one BEGIN:VEVENT per session.
BEGIN:VCALENDAR
VERSION:2.0
PRODID:-//Bevel Conf//Schedule//EN
CALSCALE:GREGORIAN
X-WR-CALNAME:Bevel Conf 2027
BEGIN:VEVENT
UID:keynote-static-first@bevel-conf.example
Your browser may download it instead of showing it. That is fine. Open the file and your calendar app offers to import eight events.

Next: 7. Ship to GitHub Pages.