using System.Text.Json.Serialization; namespace Elternbeirat.Contracts; /// /// A content page of the site, as stored in PocketBase. /// /// /// Pages also drive the site navigation: and /// decide where and in which order a page appears in the /// header or footer menu. lists dynamic blocks rendered /// below the page body. /// public record Page { /// /// The slug of the home page, which is served at the site root / rather /// than at /home. Reserved: no other page may use it. /// private const string HomeSlug = "home"; /// /// Gets the PocketBase record id. /// /// /// : every stored record has an id. Modeling it as /// required states which fields a record must carry, independent of the store, /// so a future data source has to supply them too. /// [JsonPropertyName("id")] public required string Id { get; init; } /// /// Gets the heading shown to visitors. /// /// /// Free text; may contain umlauts and spaces. For the URL, see . /// : a page without a heading is incomplete, and the /// field is required in PocketBase. /// [JsonPropertyName("title")] public required string Title { get; init; } /// /// Gets the page body as Markdown. /// [JsonPropertyName("body")] public string Body { get; init; } = string.Empty; /// /// Gets the navigation menu the page appears in. /// /// /// Either "header" or "footer". /// /// /// : the navigation is built from this, and the field /// is required in PocketBase, so every page belongs to one of the two menus. /// [JsonPropertyName("location")] public required string Location { get; init; } /// /// Gets the sort order within the navigation menu given by . /// /// /// The sort key; pages with smaller values appear first. /// [JsonPropertyName("order")] public double Order { get; init; } /// /// Gets the URL slug of the page, e.g. "board" for /board. /// /// /// A URL path segment: lowercase letters, digits and single hyphens as /// separators, no umlauts. PocketBase enforces this on save via a field /// pattern (^[a-z0-9]+(-[a-z0-9]+)*$), so every stored slug is already /// canonical and the app can use it verbatim in comparisons and generated URLs. /// /// /// : the slug is how a page is addressed, so a record /// without one is broken. It is a required field in PocketBase, so deserializing /// one that lacks it should fail loudly rather than yield a page with no URL. /// [JsonPropertyName("slug")] public required string Slug { get; init; } /// /// Gets the dynamic blocks rendered below the . /// /// /// Any of "posts", "events" and "faqs", or an empty list /// for a plain text page. /// [JsonPropertyName("embed")] public IReadOnlyList Embed { get; init; } = []; /// /// Tests whether a slug is the home page's. This is the single definition of /// that comparison, so every caller identifies the home page the same way. /// /// /// An ordinal (case-sensitive) comparison is enough because slugs are always /// lowercase: PocketBase enforces that with a field pattern (see /// ), and this is only ever called with a stored slug. /// /// /// The slug to test, e.g. from . /// /// /// if is the home page's slug. /// public static bool IsHomeSlug(string slug) => string.Equals(slug, HomeSlug, StringComparison.Ordinal); }