100 lines
3.2 KiB
C#
100 lines
3.2 KiB
C#
using System.Text.Json.Serialization;
|
|
|
|
namespace Elternbeirat.Contracts;
|
|
|
|
/// <summary>
|
|
/// A content page of the site, as stored in PocketBase.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Pages also drive the site navigation: <see cref="Location"/> and
|
|
/// <see cref="Order"/> decide where and in which order a page appears in the
|
|
/// header or footer menu. <see cref="Embed"/> lists dynamic blocks rendered
|
|
/// below the page body.
|
|
/// </remarks>
|
|
public record Page
|
|
{
|
|
/// <summary>
|
|
/// The slug of the home page, which is served at the site root <c>/</c> rather
|
|
/// than at <c>/home</c>. Reserved: no other page may use it.
|
|
/// </summary>
|
|
private const string HomeSlug = "home";
|
|
|
|
/// <summary>
|
|
/// Gets the PocketBase record id.
|
|
/// </summary>
|
|
[JsonPropertyName("id")]
|
|
public string Id { get; init; } = "";
|
|
|
|
/// <summary>
|
|
/// Gets the heading shown to visitors.
|
|
/// </summary>
|
|
/// <remarks>
|
|
/// Free text; may contain umlauts and spaces. For the URL, see <see cref="Slug"/>.
|
|
/// </remarks>
|
|
[JsonPropertyName("title")]
|
|
public string Title { get; init; } = "";
|
|
|
|
/// <summary>
|
|
/// Gets the page body as Markdown.
|
|
/// </summary>
|
|
[JsonPropertyName("body")]
|
|
public string Body { get; init; } = "";
|
|
|
|
/// <summary>
|
|
/// Gets the navigation menu the page appears in.
|
|
/// </summary>
|
|
/// <value>
|
|
/// Either <c>"header"</c> or <c>"footer"</c>.
|
|
/// </value>
|
|
[JsonPropertyName("location")]
|
|
public string Location { get; init; } = "";
|
|
|
|
/// <summary>
|
|
/// Gets the sort order within the navigation menu given by <see cref="Location"/>.
|
|
/// </summary>
|
|
/// <value>
|
|
/// The sort key; pages with smaller values appear first.
|
|
/// </value>
|
|
[JsonPropertyName("order")]
|
|
public double Order { get; init; }
|
|
|
|
/// <summary>
|
|
/// Gets the URL slug of the page, e.g. <c>"board"</c> for <c>/board</c>.
|
|
/// </summary>
|
|
/// <value>
|
|
/// A lowercase path segment without umlauts.
|
|
/// </value>
|
|
[JsonPropertyName("slug")]
|
|
public string Slug { get; init; } = "";
|
|
|
|
/// <summary>
|
|
/// Gets the dynamic blocks rendered below the <see cref="Body"/>.
|
|
/// </summary>
|
|
/// <value>
|
|
/// Any of <c>"posts"</c>, <c>"events"</c> and <c>"faqs"</c>, or an empty list
|
|
/// for a plain text page.
|
|
/// </value>
|
|
[JsonPropertyName("embed")]
|
|
public IReadOnlyList<string> Embed { get; init; } = [];
|
|
|
|
/// <summary>
|
|
/// Gets a value indicating whether the page is visible to visitors of the site.
|
|
/// </summary>
|
|
[JsonPropertyName("public")]
|
|
public bool Public { get; init; }
|
|
|
|
/// <summary>
|
|
/// Tests whether a slug is the home page's, ignoring case. This is the single
|
|
/// definition of that comparison, so every caller treats <c>home</c> and
|
|
/// <c>Home</c> alike.
|
|
/// </summary>
|
|
/// <param name="slug">
|
|
/// The slug to test.
|
|
/// </param>
|
|
/// <returns>
|
|
/// <see langword="true"/> if <paramref name="slug"/> is the home page's slug.
|
|
/// </returns>
|
|
public static bool IsHomeSlug(string slug) =>
|
|
string.Equals(slug, HomeSlug, StringComparison.OrdinalIgnoreCase);
|
|
}
|