Public Access
79 lines
2.6 KiB
C#
79 lines
2.6 KiB
C#
using MeetingAssistant.MeetingNotes;
|
|
using YamlDotNet.Serialization;
|
|
|
|
namespace MeetingAssistant.Summary;
|
|
|
|
internal static class MeetingSummaryFrontmatterFactory
|
|
{
|
|
private static readonly IDeserializer YamlDeserializer = FrontmatterYamlDeserializer.Create();
|
|
|
|
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 = CopyNonEmptyProjectList(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 List<string>? CopyNonEmptyProjectList(IEnumerable<string> values)
|
|
{
|
|
var projects = values
|
|
.Where(value => !string.IsNullOrWhiteSpace(value))
|
|
.Select(value => value.Trim())
|
|
.Distinct(StringComparer.OrdinalIgnoreCase)
|
|
.ToList();
|
|
return projects.Count == 0 ? null : projects;
|
|
}
|
|
|
|
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; }
|
|
}
|
|
}
|