Serve pages and home from PocketBase, drop the file-based content layer

This commit is contained in:
tleininger committed 2026-09-23 13:30:48 +02:00
1 parent da87716d97
commit 4136af6417
15 files changed
+117 -285

No files matched your search

@@ -1,4 +1,6 @@
using Elternbeirat.Web.Services;
using Elternbeirat.Contracts;
using Elternbeirat.PocketBase;
using Elternbeirat.Web.Shared;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Http;
@@ -6,23 +8,49 @@ namespace Elternbeirat.Web.Features.Pages;
public partial class ContentPage
{
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load page '{slug}' from PocketBase.")]
private static partial void LogLoadFailed(ILogger logger, string slug, Exception exception);
[Parameter]
public string Slug { get; set; } = "";
[Inject]
private PocketBaseClient PocketBase { get; set; } = default!;
[Inject]
private ILogger<ContentPage> Logger { get; set; } = default!;
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private Page? _page;
protected override void OnParametersSet()
{
_page = PageService.Find(Slug);
// The page body rendered from Markdown to HTML, ready to emit as a
// MarkupString in the markup.
private MarkupString Body => (MarkupString)Markdown.ToHtml(_page?.Body);
// Unknown slug -> 404, so UseStatusCodePagesWithReExecute serves the
// /not-found page instead of an empty 200 response.
protected override async Task OnParametersSetAsync()
{
try
{
var pages = await PocketBase.GetPagesAsync();
_page = pages.FirstOrDefault(
p => string.Equals(p.Slug, Slug, StringComparison.OrdinalIgnoreCase));
}
catch (HttpRequestException ex)
{
// Source unreachable -> treat as "not found" rather than a 500. The
// 404 branch below serves the friendly /not-found page.
LogLoadFailed(Logger, Slug, ex);
_page = null;
}
// Unknown slug (or unreachable source) -> 404, so
// UseStatusCodePagesWithReExecute serves the /not-found page instead of an
// empty 200 response.
if (_page is null && HttpContext is not null)
{
HttpContext.Response.StatusCode = StatusCodes.Status404NotFound;
}
}
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
}