Serve downloadable PDFs from a PocketBase documents collection

- New collection "documents" (title, slug, file, category, order, public);
  editors upload PDFs in the admin, no developer or redeploy needed
- The app serves each file at /dokumente/<slug>.pdf, a URL that survives a
  new upload (PocketBase's own file name gets a random suffix)
- New "documents" embed lists them as file cards, grouped by category;
  /downloads uses it
- List/view rules are "public = true", so a draft PDF is not reachable through
  the PocketBase API either
- Dev seed adds example documents with generated PDFs and fixes the
  const reassignment that broke seeding a fresh volume
- Docs: editor guide, architecture, and the manual production setup steps

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
TomandClaude Opus 5.5 committed 2026-10-12 22:15:18 +02:00
1 parent 97321e2b49
commit f1a06956f7
18 files changed
+641 -31

No files matched your search

@@ -0,0 +1,20 @@
@if (_groups.Count > 0)
{
@* markdown-body and the lone-link class give the entries the same file cards a
lone PDF link gets in a page body, so both look alike on /downloads. *@
<section class="embed embed-documents markdown-body">
@foreach (var group in _groups)
{
@if (group.Key.Length > 0)
{
<h2>@group.Key</h2>
}
<ul>
@foreach (var document in group)
{
<li class="@Markdown.LoneLinkClass"><a href="@document.Path">@document.Title</a></li>
}
</ul>
}
</section>
}
@@ -0,0 +1,43 @@
using Elternbeirat.Contracts;
using Elternbeirat.PocketBase;
using Microsoft.AspNetCore.Components;
namespace Elternbeirat.Web.Features.Embeds;
public partial class DocumentsEmbed
{
[LoggerMessage(
Level = LogLevel.Warning,
Message = "Could not load documents for an embed from PocketBase; the list is omitted.")]
private static partial void LogSourceUnavailable(
ILogger logger,
Exception exception);
[Inject]
private PocketBaseClient PocketBase { get; set; } = null!;
[Inject]
private ILogger<DocumentsEmbed> Logger { get; set; } = null!;
[CascadingParameter]
private HttpContext? HttpContext { get; set; }
private IReadOnlyList<IGrouping<string, Document>> _groups = [];
protected override async Task OnInitializedAsync()
{
try
{
// GroupBy keeps the groups in the order of their first document, so an
// editor orders the groups through the documents' own order field.
var documents = await PocketBase.GetDocumentsAsync(HttpContext?.RequestAborted ?? CancellationToken.None);
_groups = [.. documents.GroupBy(document => document.Category)];
}
catch (PocketBaseUnavailableException exception)
{
// Only part of the page fails: omit the list, keep the page (and its
// 200) intact.
LogSourceUnavailable(Logger, exception);
}
}
}
@@ -0,0 +1,8 @@
/* The cards come from the global app.css (the lone PDF link). Unlike the post and
event teasers, the list belongs to the page's reading column, so it takes the same
centred 42rem as ContentPage's text, whose scoped rule does not reach in here. */
.embed-documents {
max-width: 42rem;
margin-inline: auto;
margin-top: var(--space-5);
}
@@ -12,11 +12,14 @@
case "events":
<EventsEmbed />
break;
case "documents":
<DocumentsEmbed />
break;
}
}
@code {
/// <summary>The page's embed keys ("posts", "events"), in order.</summary>
/// <summary>The page's embed keys ("posts", "events", "documents"), in order.</summary>
[Parameter]
public IReadOnlyList<string> Embed { get; set; } = [];
}