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

+1 -23
View File
@@ -9,26 +9,4 @@
Antworten auf häufige Fragen und Unterlagen rund um die Elternarbeit.
</p>
<section class="home-news">
<h2>Aktuelle Beiträge</h2>
@if (_latest.Count == 0)
{
<p>Zurzeit gibt es keine Beiträge.</p>
}
else
{
<ul class="post-list">
@foreach (var post in _latest)
{
<li>
<a href="@($"/posts/{post.Slug}")">@post.Title</a>
<time datetime="@post.Date.ToString("yyyy-MM-dd")">
@post.Date.ToString("d. MMMM yyyy", German)
</time>
</li>
}
</ul>
<p><a href="/posts">Alle Beiträge &rarr;</a></p>
}
</section>
<PageEmbeds Embed="_embed" />
+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);
}
}
@@ -2,28 +2,3 @@
font-size: 1.1rem;
color: #444;
}
.home-news {
margin-top: 2rem;
}
.post-list {
list-style: none;
padding: 0;
}
.post-list li {
padding: 0.75rem 0;
border-bottom: 1px solid #eee;
}
.post-list a {
font-size: 1.1rem;
text-decoration: none;
}
.post-list time {
display: block;
color: #777;
font-size: 0.85rem;
}