Public Access
Centralize summary frontmatter metadata
PR and Push Build/Test / build-and-test (push) Successful in 9m47s
PR and Push Build/Test / build-and-test (push) Successful in 9m47s
This commit is contained in:
@@ -0,0 +1,70 @@
|
||||
using MeetingAssistant.MeetingNotes;
|
||||
using YamlDotNet.Serialization;
|
||||
|
||||
namespace MeetingAssistant.Summary;
|
||||
|
||||
internal static class MeetingSummaryFrontmatterFactory
|
||||
{
|
||||
private static readonly IDeserializer YamlDeserializer = new DeserializerBuilder()
|
||||
.IgnoreUnmatchedProperties()
|
||||
.Build();
|
||||
|
||||
public static async Task<MeetingArtifactFrontmatter> CreateAsync(
|
||||
MeetingSessionArtifacts artifacts,
|
||||
MeetingNote meetingNote,
|
||||
string title,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var frontmatter = MeetingArtifactFrontmatterRenderer.Create(
|
||||
artifacts,
|
||||
meetingNote,
|
||||
title,
|
||||
artifacts.SummaryPath);
|
||||
frontmatter.Attendees = await ResolveSummaryAttendeesAsync(
|
||||
artifacts.SummaryPath,
|
||||
meetingNote,
|
||||
cancellationToken);
|
||||
frontmatter.Projects = CopyNonEmptyList(meetingNote.Frontmatter.Projects);
|
||||
return frontmatter;
|
||||
}
|
||||
|
||||
private static async Task<List<string>?> ResolveSummaryAttendeesAsync(
|
||||
string summaryPath,
|
||||
MeetingNote meetingNote,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
var existingAttendees = await ReadExistingSummaryAttendeesAsync(summaryPath, cancellationToken);
|
||||
return existingAttendees ?? CopyNonEmptyList(meetingNote.Frontmatter.Attendees);
|
||||
}
|
||||
|
||||
private static List<string>? CopyNonEmptyList(IReadOnlyCollection<string> values)
|
||||
{
|
||||
return values.Count == 0 ? null : values.ToList();
|
||||
}
|
||||
|
||||
private static async Task<List<string>?> ReadExistingSummaryAttendeesAsync(
|
||||
string summaryPath,
|
||||
CancellationToken cancellationToken)
|
||||
{
|
||||
if (!File.Exists(summaryPath))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var content = await File.ReadAllTextAsync(summaryPath, cancellationToken);
|
||||
var document = MarkdownDocumentParser.SplitOptional(content);
|
||||
if (!document.HasFrontmatter)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
var yaml = YamlDeserializer.Deserialize<SummaryFrontmatterYaml>(document.Frontmatter);
|
||||
return yaml?.Attendees;
|
||||
}
|
||||
|
||||
private sealed class SummaryFrontmatterYaml
|
||||
{
|
||||
[YamlMember(Alias = "attendees")]
|
||||
public List<string>? Attendees { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user