diff --git a/Shared/Models/Stateless/Methods/MarkDown.cs b/Shared/Models/Stateless/Methods/MarkDown.cs index a1c94b0..7a1a687 100644 --- a/Shared/Models/Stateless/Methods/MarkDown.cs +++ b/Shared/Models/Stateless/Methods/MarkDown.cs @@ -1,4 +1,5 @@ using System.Collections.ObjectModel; +using System.Text; using System.Text.RegularExpressions; namespace View_by_Distance.Shared.Models.Stateless.Methods; @@ -10,7 +11,6 @@ internal abstract class MarkDown internal static void WriteFile(string personKeyFormatted, long ticks, Models.PersonName personName, List genealogicalDataCommunicationRelations, string a2PeopleContentDirectory, ReadOnlyDictionary personKeyFormattedToPersonFullName, ReadOnlyDictionary> familyIndexToCollection, bool isDefaultName, Models.GenealogicalDataCommunication genealogicalDataCommunication, bool first) { - string decade; string jrOrSr; string? personFullName; @@ -18,7 +18,7 @@ internal abstract class MarkDown const char mother = 'M'; bool hasRelation = false; const string wife = "WIFE"; - string lowerHyphenRelation; + StringBuilder link = new(); const string child = "CHIL"; const string husband = "HUSB"; const string person = "person"; @@ -30,12 +30,12 @@ internal abstract class MarkDown List lines = new() { "---", - $"type: {person}", + $"type: '{person}'", $"created: {now}", $"updated: {now}", $"draft: false", $"title: '{fullName}'", - $"{nameof(fullName)}: '{fullName}'", + $"{nameof(lowerHyphenFullName)}: '{lowerHyphenFullName}'", }; if (string.IsNullOrEmpty(personName.Alias.Value)) jrOrSr = string.Empty; @@ -77,10 +77,12 @@ internal abstract class MarkDown lines.Add($"{nameof(personKeyFormatted)}: '{personKeyFormatted}'"); lines.Add("---"); lines.Add(string.Empty); - lines.Add($"# {lowerHyphenFullName}"); + lines.Add($"# {fullName}"); lines.Add(string.Empty); foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in genealogicalDataCommunicationRelations) { + if (genealogicalDataCommunication?.NickName is null || genealogicalDataCommunication.NickName.Length < 4) + continue; if (genealogicalDataCommunicationRelation.Relation != child) continue; if (genealogicalDataCommunicationRelation.NickName != personKeyFormatted) @@ -100,28 +102,40 @@ internal abstract class MarkDown hasRelation = true; } decade = relation.NickName[..3]; + _ = link.Clear(); + _ = link.Append("- ["); if (!personKeyFormattedToPersonFullName.TryGetValue(relation.NickName, out personFullName)) - lowerHyphenRelation = relation.NickName; + _ = link.Append(relation.NickName); else - lowerHyphenRelation = Regex.Replace(personFullName.ToLower(), "[^a-z0-9-]", "-").Replace("--", "-"); + _ = link.Append(personFullName); + if (genealogicalDataCommunication.NickName[..3] == decade) + _ = link.Append("]("); + else + _ = link.Append("](../").Append(decade).Append('/'); + if (personFullName is null) + _ = link.Append(relation.NickName); + else + _ = link.Append(Regex.Replace(personFullName.ToLower(), "[^a-z0-9-]", "-").Replace("--", "-")); + _ = link.Append(".md) "); if (string.IsNullOrEmpty(genealogicalDataCommunicationRelation.LineTwo)) - lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]]"); + lines.Add(link.ToString()); else { if (genealogicalDataCommunicationRelation.LineTwo[1] == father) { if (relation.Relation == wife) - lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]] {nameof(mother)}"); + _ = link.Append(nameof(mother)); else if (relation.Relation == husband) - lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(father)}"); + _ = link.Append(genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()).Append(nameof(father)); } else if (genealogicalDataCommunicationRelation.LineTwo[1] == mother) { if (relation.Relation == husband) - lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]] {nameof(father)}"); + _ = link.Append(nameof(father)); else if (relation.Relation == wife) - lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(mother)}"); + _ = link.Append(genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()).Append(nameof(mother)); } + lines.Add(link.ToString()); } } }