Add news post type with list and detail routes

This commit is contained in:
tleininger committed 2026-09-21 15:47:12 +02:00
1 parent bed2db5972
commit 908a03a1f6
10 files changed
+295 -31

No files matched your search

+42
View File
@@ -0,0 +1,42 @@
using Markdig;
using Markdig.Extensions.Yaml;
using Markdig.Syntax;
namespace Elternbeirat.Web.Services;
/// <summary>
/// Reads simple <c>key: value</c> pairs from a Markdown file's YAML front
/// matter. Kept deliberately minimal (one value per line, no nesting) — this is
/// enough for titles and dates. YamlDotNet will take over once we need
/// structured metadata. Front-matter keys stay German because the Markdown
/// files are edited by German-speaking editors.
/// </summary>
public static class FrontMatter
{
/// <summary>
/// Returns the value of the given front-matter key, or <c>null</c> if the
/// file has no front matter or the key is missing. The key match is
/// case-insensitive; surrounding quotes on the value are removed.
/// </summary>
public static string? Read(string key, MarkdownDocument document, string source)
{
var block = document.Descendants<YamlFrontMatterBlock>().FirstOrDefault();
if (block is null)
{
return null;
}
var prefix = key + ":";
var frontMatter = source.Substring(block.Span.Start, block.Span.Length);
foreach (var line in frontMatter.Split('\n'))
{
var trimmed = line.Trim();
if (trimmed.StartsWith(prefix, StringComparison.OrdinalIgnoreCase))
{
return trimmed[prefix.Length..].Trim().Trim('"');
}
}
return null;
}
}