Generate navigation and render page embeds from PocketBase

This commit is contained in:
tleininger committed 2026-09-23 14:54:10 +02:00
1 parent 6b5d9dda55
commit 3fd3796d73
26 files changed
+544 -114

No files matched your search

+9 -10
View File
@@ -1,5 +1,3 @@
using System.Globalization;
using Elternbeirat.Contracts;
using Elternbeirat.PocketBase;
using Microsoft.AspNetCore.Components;
@@ -7,9 +5,7 @@ namespace Elternbeirat.Web.Features.Home;
public partial class Home
{
private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE");
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load posts for the home teaser from PocketBase.")]
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load the home page from PocketBase.")]
private static partial void LogLoadFailed(ILogger logger, Exception exception);
[Inject]
@@ -18,19 +14,22 @@ public partial class Home
[Inject]
private ILogger<Home> Logger { get; set; } = default!;
private IReadOnlyList<Post> _latest = [];
// Which dynamic blocks the home page shows is editorial: it comes from the
// "home" page's embed field in PocketBase, not from hard-coded markup.
private IReadOnlyList<string> _embed = [];
protected override async Task OnInitializedAsync()
{
try
{
// Show the three most recent posts as a teaser on the home page.
var posts = await PocketBase.GetPostsAsync();
_latest = [.. posts.Take(3)];
var pages = await PocketBase.GetPagesAsync();
var home = pages.FirstOrDefault(
p => string.Equals(p.Slug, "home", StringComparison.Ordinal));
_embed = home?.Embed ?? [];
}
catch (HttpRequestException ex)
{
// Source unreachable -> show no teaser instead of a 500.
// Source unreachable -> render the intro without embeds instead of a 500.
LogLoadFailed(Logger, ex);
}
}