Read heading and intro from the pages record on /posts and /events

This commit is contained in:
tleininger committed 2026-09-30 21:33:26 +02:00
1 parent 666614a3b2
commit 4fa17429b5
7 files changed
+87 -7

No files matched your search

@@ -1,8 +1,19 @@
@page "/events"
<PageTitle>Termine</PageTitle>
@{
// Heading and intro come from the "events" page record; fall back to a sensible
// default only if that record is missing, so the page still renders.
var title = _page?.Title ?? "Termine";
}
<h1>Termine</h1>
<PageTitle>@title</PageTitle>
<h1>@title</h1>
@if (_page is not null && !string.IsNullOrWhiteSpace(_page.Body))
{
<article>@Body</article>
}
@if (_unavailable)
{
@@ -23,6 +23,11 @@ public partial class EventList
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
// The "events" page record supplies the heading and intro text, so an editor
// owns them in PocketBase like every other page, instead of them being
// hard-coded here. Null until loaded, or when no such page exists.
private Page? _page;
private IReadOnlyList<Event> _upcomingEvents = [];
private IReadOnlyList<Event> _pastEvents = [];
@@ -31,12 +36,19 @@ public partial class EventList
// 503 this sets on the response.
private bool _unavailable;
// The page body rendered from Markdown to HTML, ready to emit as a MarkupString.
private MarkupString Body => (MarkupString)Markdown.ToHtml(_page?.Body);
protected override async Task OnInitializedAsync()
{
IReadOnlyList<Event> events;
try
{
events = await PocketBase.GetEventsAsync(HttpContext?.RequestAborted ?? CancellationToken.None);
var token = HttpContext?.RequestAborted ?? CancellationToken.None;
var pages = await PocketBase.GetPagesAsync(token);
_page = pages.FirstOrDefault(
page => string.Equals(page.Slug, "events", StringComparison.OrdinalIgnoreCase));
events = await PocketBase.GetEventsAsync(token);
}
catch (PocketBaseUnavailableException exception)
{