Consume PocketBase for posts and events, with English routes
This commit is contained in:
1 parent
c59e7a4f83
commit
da87716d97
22 files changed
+278
-225
No files matched your search
@@ -8,8 +8,8 @@
|
||||
<NavLink href="/" Match="NavLinkMatch.All">Start</NavLink>
|
||||
<NavLink href="/vorstandsteam">Vorstandsteam</NavLink>
|
||||
<NavLink href="/foerderverein">Förderverein</NavLink>
|
||||
<NavLink href="/beitraege">Beiträge</NavLink>
|
||||
<NavLink href="/termine">Termine</NavLink>
|
||||
<NavLink href="/posts">Beiträge</NavLink>
|
||||
<NavLink href="/events">Termine</NavLink>
|
||||
<NavLink href="/faq">FAQ</NavLink>
|
||||
<NavLink href="/downloads">Downloads</NavLink>
|
||||
<NavLink href="/kontakt">Kontakt</NavLink>
|
||||
|
||||
@@ -22,6 +22,12 @@
|
||||
<PackageReference Include="YamlDotNet" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- The typed PocketBaseClient the app reads its content from. Referencing
|
||||
PocketBase brings in Elternbeirat.Contracts (the DTOs) transitively. -->
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\Elternbeirat.PocketBase\Elternbeirat.PocketBase.csproj" />
|
||||
</ItemGroup>
|
||||
|
||||
<!-- Content ships as files inside the image, not in a volume. Copy it to
|
||||
the output directory so the container can find it. -->
|
||||
<ItemGroup>
|
||||
|
||||
@@ -1,33 +0,0 @@
|
||||
namespace Elternbeirat.Web.Features.Events;
|
||||
|
||||
/// <summary>
|
||||
/// A single calendar entry (parents' evening, meeting, deadline). Read from
|
||||
/// <c>Content/events.yml</c> at startup. All display text is German because it
|
||||
/// is visitor-facing content.
|
||||
/// </summary>
|
||||
public sealed class Event
|
||||
{
|
||||
/// <summary>Short title shown in the list and the calendar.</summary>
|
||||
public required string Title { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// When the entry starts. A date-only entry (no time) is treated as an
|
||||
/// all-day event; see <see cref="HasTime"/>.
|
||||
/// </summary>
|
||||
public required DateTime Start { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// True when <see cref="Start"/> carries a wall-clock time, false for an
|
||||
/// all-day entry. Drives both the list formatting and the ICS export.
|
||||
/// </summary>
|
||||
public required bool HasTime { get; init; }
|
||||
|
||||
/// <summary>Optional end, for multi-hour or multi-day entries.</summary>
|
||||
public DateTime? End { get; init; }
|
||||
|
||||
/// <summary>Optional location, e.g. "Aula" or "Mensa".</summary>
|
||||
public string? Location { get; init; }
|
||||
|
||||
/// <summary>Optional free-text note shown below the entry.</summary>
|
||||
public string? Note { get; init; }
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
@page "/termine"
|
||||
@inject EventService EventService
|
||||
@page "/events"
|
||||
|
||||
<PageTitle>Termine</PageTitle>
|
||||
|
||||
@@ -7,20 +6,20 @@
|
||||
|
||||
<p class="intro">
|
||||
Alle Termine des Elternbeirats auf einen Blick. Sie können den Kalender auch
|
||||
<a href="/termine.ics">abonnieren</a> und in Ihrer Kalender-App automatisch
|
||||
<a href="/events.ics">abonnieren</a> und in Ihrer Kalender-App automatisch
|
||||
aktuell halten.
|
||||
</p>
|
||||
|
||||
<h2>Kommende Termine</h2>
|
||||
|
||||
@if (EventService.Upcoming.Count == 0)
|
||||
@if (_upcoming.Count == 0)
|
||||
{
|
||||
<p>Zurzeit sind keine Termine geplant.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="event-list">
|
||||
@foreach (var ev in EventService.Upcoming)
|
||||
@foreach (var ev in _upcoming)
|
||||
{
|
||||
<li>
|
||||
<time datetime="@ev.Start.ToString("s")">@Format(ev)</time>
|
||||
@@ -38,11 +37,11 @@ else
|
||||
</ul>
|
||||
}
|
||||
|
||||
@if (EventService.Past.Count > 0)
|
||||
@if (_past.Count > 0)
|
||||
{
|
||||
<h2>Vergangene Termine</h2>
|
||||
<ul class="event-list event-list-past">
|
||||
@foreach (var ev in EventService.Past)
|
||||
@foreach (var ev in _past)
|
||||
{
|
||||
<li>
|
||||
<time datetime="@ev.Start.ToString("s")">@Format(ev)</time>
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Globalization;
|
||||
using Elternbeirat.Web.Services;
|
||||
using Elternbeirat.Contracts;
|
||||
using Elternbeirat.PocketBase;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Elternbeirat.Web.Features.Events;
|
||||
|
||||
@@ -7,11 +9,55 @@ public partial class EventList
|
||||
{
|
||||
private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE");
|
||||
|
||||
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load events from PocketBase.")]
|
||||
private static partial void LogLoadFailed(ILogger logger, Exception exception);
|
||||
|
||||
[Inject]
|
||||
private PocketBaseClient PocketBase { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
private ILogger<EventList> Logger { get; set; } = default!;
|
||||
|
||||
private IReadOnlyList<Event> _upcoming = [];
|
||||
private IReadOnlyList<Event> _past = [];
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
IReadOnlyList<Event> events;
|
||||
try
|
||||
{
|
||||
events = await PocketBase.GetEventsAsync();
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
// Source unreachable -> show empty sections instead of a 500. The page
|
||||
// stays up; the "keine Termine" note is rendered.
|
||||
LogLoadFailed(Logger, ex);
|
||||
return;
|
||||
}
|
||||
|
||||
// Split into upcoming and past by date, so an event earlier today still
|
||||
// counts as upcoming. Upcoming earliest first, past most recent first.
|
||||
var today = DateOnly.FromDateTime(DateTime.Today);
|
||||
_upcoming = events
|
||||
.Where(e => DateOnly.FromDateTime(e.Start) >= today)
|
||||
.OrderBy(e => e.Start)
|
||||
.ToList();
|
||||
_past = events
|
||||
.Where(e => DateOnly.FromDateTime(e.Start) < today)
|
||||
.OrderByDescending(e => e.Start)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
// An event counts as all-day when its start carries no wall-clock time
|
||||
// (00:00); PocketBase has no separate flag.
|
||||
private static bool HasTime(Event ev) => ev.Start.TimeOfDay != TimeSpan.Zero;
|
||||
|
||||
// Formats the entry's date range for display: a single day, a date with a
|
||||
// time, or a span across days.
|
||||
private static string Format(Event ev)
|
||||
{
|
||||
var start = ev.HasTime
|
||||
var start = HasTime(ev)
|
||||
? ev.Start.ToString("dddd, d. MMMM yyyy, HH:mm", German) + " Uhr"
|
||||
: ev.Start.ToString("dddd, d. MMMM yyyy", German);
|
||||
|
||||
@@ -24,12 +70,12 @@ public partial class EventList
|
||||
// end date.
|
||||
if (end.Date == ev.Start.Date)
|
||||
{
|
||||
return ev.HasTime
|
||||
return HasTime(ev)
|
||||
? start + "–" + end.ToString("HH:mm", German) + " Uhr"
|
||||
: start;
|
||||
}
|
||||
|
||||
var endText = ev.HasTime
|
||||
var endText = HasTime(ev)
|
||||
? end.ToString("d. MMMM yyyy, HH:mm", German) + " Uhr"
|
||||
: end.ToString("d. MMMM yyyy", German);
|
||||
return start + " – " + endText;
|
||||
|
||||
@@ -1,138 +0,0 @@
|
||||
using System.Globalization;
|
||||
using Elternbeirat.Web.Services;
|
||||
using YamlDotNet.Serialization;
|
||||
using YamlDotNet.Serialization.NamingConventions;
|
||||
|
||||
namespace Elternbeirat.Web.Features.Events;
|
||||
|
||||
/// <summary>
|
||||
/// Reads the calendar entries from <c>Content/events.yml</c> once at startup and
|
||||
/// keeps them in memory. Registered as a singleton because the content lives in
|
||||
/// the image and does not change at runtime.
|
||||
/// </summary>
|
||||
public sealed class EventService
|
||||
{
|
||||
private readonly IReadOnlyList<Event> _events;
|
||||
|
||||
/// <summary>
|
||||
/// Reads and parses <c>Content/events.yml</c> below the application root.
|
||||
/// A missing file yields an empty list rather than an error.
|
||||
/// </summary>
|
||||
public EventService(IWebHostEnvironment environment)
|
||||
{
|
||||
var path = Path.Combine(environment.ContentRootPath, "Content", "events.yml");
|
||||
_events = File.Exists(path)
|
||||
? Parse(File.ReadAllText(path))
|
||||
: [];
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Entries that start today or later, earliest first — the upcoming section.
|
||||
/// "Today" is compared by date, so an entry earlier today still counts as
|
||||
/// upcoming.
|
||||
/// </summary>
|
||||
public IReadOnlyList<Event> Upcoming =>
|
||||
_events
|
||||
.Where(e => DateOnly.FromDateTime(e.Start) >= DateOnly.FromDateTime(DateTime.Today))
|
||||
.OrderBy(e => e.Start)
|
||||
.ToList();
|
||||
|
||||
/// <summary>
|
||||
/// Entries that already passed, most recent first — the past section shown
|
||||
/// below the upcoming ones.
|
||||
/// </summary>
|
||||
public IReadOnlyList<Event> Past =>
|
||||
_events
|
||||
.Where(e => DateOnly.FromDateTime(e.Start) < DateOnly.FromDateTime(DateTime.Today))
|
||||
.OrderByDescending(e => e.Start)
|
||||
.ToList();
|
||||
|
||||
/// <summary>All entries in chronological order, for the ICS export.</summary>
|
||||
public IReadOnlyList<Event> All =>
|
||||
_events.OrderBy(e => e.Start).ToList();
|
||||
|
||||
private static List<Event> Parse(string yaml)
|
||||
{
|
||||
// Keys are lowercase single words (title, start, ...), which the camel
|
||||
// case convention maps onto the PascalCase properties.
|
||||
var deserializer = new DeserializerBuilder()
|
||||
.WithNamingConvention(CamelCaseNamingConvention.Instance)
|
||||
.IgnoreUnmatchedProperties()
|
||||
.Build();
|
||||
|
||||
var raw = deserializer.Deserialize<List<EventEntry>?>(yaml) ?? [];
|
||||
return raw
|
||||
.Where(entry => entry.Title is not null && entry.Start is not null)
|
||||
.Select(ToEvent)
|
||||
.OfType<Event>()
|
||||
.ToList();
|
||||
}
|
||||
|
||||
private static Event? ToEvent(EventEntry entry)
|
||||
{
|
||||
if (!TryParseWhen(entry.Start!, out var start, out var hasTime))
|
||||
{
|
||||
// A malformed date drops the entry rather than crashing startup.
|
||||
return null;
|
||||
}
|
||||
|
||||
DateTime? end = null;
|
||||
if (entry.End is not null && TryParseWhen(entry.End, out var parsedEnd, out _))
|
||||
{
|
||||
end = parsedEnd;
|
||||
}
|
||||
|
||||
return new Event
|
||||
{
|
||||
Title = entry.Title!,
|
||||
Start = start,
|
||||
HasTime = hasTime,
|
||||
End = end,
|
||||
Location = entry.Location,
|
||||
Note = entry.Note,
|
||||
};
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Parses a value that is either a date (<c>2026-03-15</c>) or a date with a
|
||||
/// time (<c>2026-03-15 19:30</c>). Sets <paramref name="hasTime"/> so the
|
||||
/// caller knows whether to treat the entry as all-day.
|
||||
/// </summary>
|
||||
private static bool TryParseWhen(string value, out DateTime when, out bool hasTime)
|
||||
{
|
||||
var trimmed = value.Trim();
|
||||
|
||||
if (DateOnly.TryParseExact(trimmed, "yyyy-MM-dd",
|
||||
CultureInfo.InvariantCulture, DateTimeStyles.None, out var dateOnly))
|
||||
{
|
||||
when = dateOnly.ToDateTime(TimeOnly.MinValue);
|
||||
hasTime = false;
|
||||
return true;
|
||||
}
|
||||
|
||||
string[] formats = ["yyyy-MM-dd HH:mm", "yyyy-MM-dd'T'HH:mm"];
|
||||
if (DateTime.TryParseExact(trimmed, formats,
|
||||
CultureInfo.InvariantCulture, DateTimeStyles.None, out when))
|
||||
{
|
||||
hasTime = true;
|
||||
return true;
|
||||
}
|
||||
|
||||
when = default;
|
||||
hasTime = false;
|
||||
return false;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Raw shape of one YAML entry, before validation. String-typed on purpose so
|
||||
/// we control date parsing and can distinguish date-only from date-and-time.
|
||||
/// </summary>
|
||||
private sealed class EventEntry
|
||||
{
|
||||
public string? Title { get; set; }
|
||||
public string? Start { get; set; }
|
||||
public string? End { get; set; }
|
||||
public string? Location { get; set; }
|
||||
public string? Note { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,7 @@
|
||||
using System.Globalization;
|
||||
using System.Security.Cryptography;
|
||||
using System.Text;
|
||||
using Elternbeirat.Web.Services;
|
||||
using Elternbeirat.Contracts;
|
||||
|
||||
namespace Elternbeirat.Web.Features.Events;
|
||||
|
||||
@@ -45,7 +45,7 @@ public static class IcsCalendar
|
||||
// between requests, so caches and clients do not see spurious changes.
|
||||
AppendLine(sb, "DTSTAMP:20000101T000000Z");
|
||||
|
||||
if (ev.HasTime)
|
||||
if (HasTime(ev))
|
||||
{
|
||||
AppendLine(sb, $"DTSTART:{Local(ev.Start)}");
|
||||
if (ev.End is { } end)
|
||||
@@ -75,6 +75,12 @@ public static class IcsCalendar
|
||||
AppendLine(sb, "END:VEVENT");
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// An entry counts as all-day when its start has no wall-clock time (00:00).
|
||||
/// PocketBase has no separate flag; the convention is a midnight start.
|
||||
/// </summary>
|
||||
private static bool HasTime(Event ev) => ev.Start.TimeOfDay != TimeSpan.Zero;
|
||||
|
||||
/// <summary>
|
||||
/// A UID that stays the same as long as the entry's title and start do, so a
|
||||
/// re-subscribe updates the event instead of creating a duplicate.
|
||||
|
||||
@@ -23,13 +23,13 @@
|
||||
@foreach (var post in _latest)
|
||||
{
|
||||
<li>
|
||||
<a href="@($"/beitraege/{post.Slug}")">@post.Title</a>
|
||||
<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="/beitraege">Alle Beiträge →</a></p>
|
||||
<p><a href="/posts">Alle Beiträge →</a></p>
|
||||
}
|
||||
</section>
|
||||
@@ -1,5 +1,4 @@
|
||||
@page "/beitraege/{Slug}"
|
||||
@inject PostService PostService
|
||||
@page "/posts/{Slug}"
|
||||
|
||||
@if (_post is null)
|
||||
{
|
||||
@@ -10,11 +9,11 @@ else
|
||||
<PageTitle>@_post.Title</PageTitle>
|
||||
<article>
|
||||
<p class="post-meta">
|
||||
<a href="/beitraege">← Alle Beiträge</a>
|
||||
<a href="/posts">← Alle Beiträge</a>
|
||||
<time datetime="@_post.Date.ToString("yyyy-MM-dd")">
|
||||
@_post.Date.ToString("d. MMMM yyyy", German)
|
||||
</time>
|
||||
</p>
|
||||
@((MarkupString)_post.ContentHtml)
|
||||
@Body
|
||||
</article>
|
||||
}
|
||||
@@ -1,5 +1,7 @@
|
||||
using System.Globalization;
|
||||
using Elternbeirat.Web.Services;
|
||||
using Elternbeirat.Contracts;
|
||||
using Elternbeirat.PocketBase;
|
||||
using Elternbeirat.Web.Shared;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
using Microsoft.AspNetCore.Http;
|
||||
|
||||
@@ -9,23 +11,49 @@ public partial class PostDetail
|
||||
{
|
||||
private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE");
|
||||
|
||||
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load post '{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<PostDetail> Logger { get; set; } = default!;
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
|
||||
private Post? _post;
|
||||
|
||||
protected override void OnParametersSet()
|
||||
{
|
||||
_post = PostService.Find(Slug);
|
||||
// The post body rendered from Markdown to HTML, ready to emit as a
|
||||
// MarkupString in the markup.
|
||||
private MarkupString Body => (MarkupString)Markdown.ToHtml(_post?.Body);
|
||||
|
||||
// Unknown slug -> 404, so UseStatusCodePagesWithReExecute serves the
|
||||
// /not-found page instead of an empty 200 response.
|
||||
protected override async Task OnParametersSetAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
var posts = await PocketBase.GetPostsAsync();
|
||||
_post = posts.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);
|
||||
_post = null;
|
||||
}
|
||||
|
||||
// Unknown slug (or unreachable source) -> 404, so
|
||||
// UseStatusCodePagesWithReExecute serves the /not-found page instead of an
|
||||
// empty 200 response.
|
||||
if (_post is null && HttpContext is not null)
|
||||
{
|
||||
HttpContext.Response.StatusCode = StatusCodes.Status404NotFound;
|
||||
}
|
||||
}
|
||||
|
||||
[CascadingParameter]
|
||||
private HttpContext? HttpContext { get; set; }
|
||||
}
|
||||
@@ -1,21 +1,20 @@
|
||||
@page "/beitraege"
|
||||
@inject PostService PostService
|
||||
@page "/posts"
|
||||
|
||||
<PageTitle>Beiträge</PageTitle>
|
||||
|
||||
<h1>Beiträge</h1>
|
||||
|
||||
@if (PostService.All.Count == 0)
|
||||
@if (_posts.Count == 0)
|
||||
{
|
||||
<p>Zurzeit gibt es keine Beiträge.</p>
|
||||
}
|
||||
else
|
||||
{
|
||||
<ul class="post-list">
|
||||
@foreach (var post in PostService.All)
|
||||
@foreach (var post in _posts)
|
||||
{
|
||||
<li>
|
||||
<a href="@($"/beitraege/{post.Slug}")">@post.Title</a>
|
||||
<a href="@($"/posts/{post.Slug}")">@post.Title</a>
|
||||
<time datetime="@post.Date.ToString("yyyy-MM-dd")">
|
||||
@post.Date.ToString("d. MMMM yyyy", German)
|
||||
</time>
|
||||
|
||||
@@ -1,8 +1,36 @@
|
||||
using System.Globalization;
|
||||
using Elternbeirat.Contracts;
|
||||
using Elternbeirat.PocketBase;
|
||||
using Microsoft.AspNetCore.Components;
|
||||
|
||||
namespace Elternbeirat.Web.Features.Posts;
|
||||
|
||||
public partial class PostList
|
||||
{
|
||||
[LoggerMessage(Level = LogLevel.Warning, Message = "Could not load posts from PocketBase.")]
|
||||
private static partial void LogLoadFailed(ILogger logger, Exception exception);
|
||||
|
||||
private static readonly CultureInfo German = CultureInfo.GetCultureInfo("de-DE");
|
||||
|
||||
[Inject]
|
||||
private PocketBaseClient PocketBase { get; set; } = default!;
|
||||
|
||||
[Inject]
|
||||
private ILogger<PostList> Logger { get; set; } = default!;
|
||||
|
||||
private IReadOnlyList<Post> _posts = [];
|
||||
|
||||
protected override async Task OnInitializedAsync()
|
||||
{
|
||||
try
|
||||
{
|
||||
_posts = await PocketBase.GetPostsAsync();
|
||||
}
|
||||
catch (HttpRequestException ex)
|
||||
{
|
||||
// Source unreachable -> show an empty list instead of a 500. The page
|
||||
// stays up; the "keine Beiträge" note is rendered.
|
||||
LogLoadFailed(Logger, ex);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,5 @@
|
||||
using Elternbeirat.Contracts;
|
||||
using Elternbeirat.PocketBase;
|
||||
using Elternbeirat.Web.Components;
|
||||
using Elternbeirat.Web.Features.Events;
|
||||
using Elternbeirat.Web.Services;
|
||||
@@ -8,10 +10,17 @@ var builder = WebApplication.CreateBuilder(args);
|
||||
// Add services to the container.
|
||||
builder.Services.AddRazorComponents();
|
||||
|
||||
// The typed client reads content from PocketBase over its REST API. The base URL
|
||||
// comes from configuration: appsettings for local dev, the PocketBase__BaseUrl
|
||||
// env var on the server (see compose.yaml).
|
||||
var pocketBaseUrl = builder.Configuration["PocketBase:BaseUrl"]
|
||||
?? throw new InvalidOperationException("PocketBase:BaseUrl is not configured.");
|
||||
builder.Services.AddHttpClient<PocketBaseClient>(client =>
|
||||
client.BaseAddress = new Uri(pocketBaseUrl));
|
||||
|
||||
// Content is read once at startup and cached -> singletons.
|
||||
builder.Services.AddSingleton<PageService>();
|
||||
builder.Services.AddSingleton<PostService>();
|
||||
builder.Services.AddSingleton<EventService>();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
@@ -43,8 +52,21 @@ app.MapStaticAssets();
|
||||
app.MapRazorComponents<App>();
|
||||
|
||||
// Subscribable calendar feed of all events. A minimal API endpoint rather than
|
||||
// a Razor page because it returns text/calendar, not HTML.
|
||||
app.MapGet("/termine.ics", (EventService events) =>
|
||||
Results.Text(IcsCalendar.Build(events.All), "text/calendar; charset=utf-8"));
|
||||
// a Razor page because it returns text/calendar, not HTML. Reads from PocketBase
|
||||
// per request; an unreachable source yields an empty calendar, not a 500.
|
||||
app.MapGet("/events.ics", async (PocketBaseClient pocketBase) =>
|
||||
{
|
||||
IReadOnlyList<Event> events;
|
||||
try
|
||||
{
|
||||
events = await pocketBase.GetEventsAsync();
|
||||
}
|
||||
catch (HttpRequestException)
|
||||
{
|
||||
events = [];
|
||||
}
|
||||
|
||||
return Results.Text(IcsCalendar.Build(events), "text/calendar; charset=utf-8");
|
||||
});
|
||||
|
||||
app.Run();
|
||||
@@ -0,0 +1,23 @@
|
||||
using Markdig;
|
||||
|
||||
namespace Elternbeirat.Web.Shared;
|
||||
|
||||
/// <summary>
|
||||
/// Renders Markdown to HTML. Content now comes from PocketBase as raw Markdown
|
||||
/// (the <c>body</c> field), so the pages render it at display time instead of
|
||||
/// reading pre-rendered HTML from files.
|
||||
/// </summary>
|
||||
public static class Markdown
|
||||
{
|
||||
private static readonly MarkdownPipeline Pipeline =
|
||||
new MarkdownPipelineBuilder().Build();
|
||||
|
||||
/// <summary>
|
||||
/// Converts a Markdown string to HTML. Returns an empty string for
|
||||
/// <c>null</c> or empty input, so callers can bind the result directly.
|
||||
/// </summary>
|
||||
public static string ToHtml(string? markdown) =>
|
||||
string.IsNullOrEmpty(markdown)
|
||||
? ""
|
||||
: Markdig.Markdown.ToHtml(markdown, Pipeline);
|
||||
}
|
||||
@@ -8,3 +8,4 @@
|
||||
@using Microsoft.JSInterop
|
||||
@using Elternbeirat.Web
|
||||
@using Elternbeirat.Web.Services
|
||||
@using Elternbeirat.Web.Shared
|
||||
@@ -4,5 +4,8 @@
|
||||
"Default": "Information",
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"PocketBase": {
|
||||
"BaseUrl": "http://localhost:8090"
|
||||
}
|
||||
}
|
||||
@@ -5,5 +5,10 @@
|
||||
"Microsoft.AspNetCore": "Warning"
|
||||
}
|
||||
},
|
||||
"AllowedHosts": "*"
|
||||
"AllowedHosts": "*",
|
||||
"PocketBase": {
|
||||
// The PocketBase service name on the compose network. compose.yaml overrides
|
||||
// this via the env var PocketBase__BaseUrl; local dev uses appsettings.Development.json.
|
||||
"BaseUrl": "http://eb-pocketbase:8090"
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user