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

@@ -23,6 +23,11 @@ public partial class PostList
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
// The "posts" 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<Post> _posts = [];
// Set when the content source could not be reached or read. The markup then
@@ -30,11 +35,18 @@ public partial class PostList
// 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()
{
try
{
_posts = await PocketBase.GetPostsAsync(HttpContext?.RequestAborted ?? CancellationToken.None);
var token = HttpContext?.RequestAborted ?? CancellationToken.None;
var pages = await PocketBase.GetPagesAsync(token);
_page = pages.FirstOrDefault(
page => string.Equals(page.Slug, "posts", StringComparison.OrdinalIgnoreCase));
_posts = await PocketBase.GetPostsAsync(token);
}
catch (PocketBaseUnavailableException exception)
{