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

+1 -30
View File
@@ -1,6 +1,4 @@
using Markdig;
using Markdig.Extensions.Yaml;
using Markdig.Syntax;
namespace Elternbeirat.Web.Services;
@@ -51,36 +49,9 @@ public sealed class PageService
var source = File.ReadAllText(path);
var document = Markdown.Parse(source, pipeline);
var title = ReadTitle(document, source) ?? slug;
var title = FrontMatter.Read("titel", document, source) ?? slug;
var html = Markdown.ToHtml(source, pipeline);
return new Page { Slug = slug, Title = title, ContentHtml = html };
}
/// <summary>
/// Pulls the <c>titel:</c> value out of the YAML front matter. Kept
/// deliberately simple (a single <c>key: value</c> line) — YamlDotNet will
/// take over once we need structured metadata. The key stays German because
/// the Markdown files are edited by German-speaking editors.
/// </summary>
private static string? ReadTitle(MarkdownDocument document, string source)
{
var block = document.Descendants<YamlFrontMatterBlock>().FirstOrDefault();
if (block is null)
{
return null;
}
var frontMatter = source.Substring(block.Span.Start, block.Span.Length);
foreach (var line in frontMatter.Split('\n'))
{
var trimmed = line.Trim();
if (trimmed.StartsWith("titel:", StringComparison.OrdinalIgnoreCase))
{
return trimmed["titel:".Length..].Trim().Trim('"');
}
}
return null;
}
}