diff --git a/Shared/Models/Stateless/Methods/MarkDown.cs b/Shared/Models/Stateless/Methods/MarkDown.cs index 3f291dc..a1c94b0 100644 --- a/Shared/Models/Stateless/Methods/MarkDown.cs +++ b/Shared/Models/Stateless/Methods/MarkDown.cs @@ -8,14 +8,35 @@ 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 fullName, string lowerHyphenFullName) + 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; + const char father = 'F'; + const char mother = 'M'; bool hasRelation = false; + const string wife = "WIFE"; string lowerHyphenRelation; + const string child = "CHIL"; + const string husband = "HUSB"; + const string person = "person"; + string fullName = PersonName.GetFullName(personName); List? relations; string now = DateTime.Now.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ"); - string jrOrSr; + string lowerHyphenFullName = $"{Regex.Replace(fullName.ToLower(), "[^a-z0-9-]", "-")}"; + string code = IPersonBirthday.GetHour(genealogicalDataCommunication.Death is null, genealogicalDataCommunication.Sex).ToString("00"); + List lines = new() + { + "---", + $"type: {person}", + $"created: {now}", + $"updated: {now}", + $"draft: false", + $"title: '{fullName}'", + $"{nameof(fullName)}: '{fullName}'", + }; if (string.IsNullOrEmpty(personName.Alias.Value)) jrOrSr = string.Empty; else @@ -27,20 +48,9 @@ internal abstract class MarkDown else jrOrSr = string.Empty; } - string code = IPersonBirthday.GetHour(genealogicalDataCommunication.Death is null, genealogicalDataCommunication.Sex).ToString("00"); + lines.Add($"name: '{personName.First.Value} /{personName.Last.Value}/{jrOrSr}'"); if (first && !personKeyFormatted.EndsWith(code)) personKeyFormatted = $"{personKeyFormatted[..^2]}{code}"; - List lines = new() - { - "---", - "type: person", - $"created: {now}", - $"updated: {now}", - $"draft: false", - $"title: '{fullName}'", - $"{nameof(fullName)}: '{fullName}'", - $"name: '{personName.First.Value} /{personName.Last.Value}/{jrOrSr}'", - }; if (!string.IsNullOrEmpty(personName.First.Value)) lines.Add($"given: '{personName.First.Value}'"); if (!string.IsNullOrEmpty(personName.Last.Value)) @@ -64,17 +74,11 @@ internal abstract class MarkDown } if (isDefaultName) lines.Add($"{nameof(isDefaultName)}: {isDefaultName}"); - lines.Add($"{nameof(personKeyFormatted)}: {personKeyFormatted}"); + lines.Add($"{nameof(personKeyFormatted)}: '{personKeyFormatted}'"); lines.Add("---"); lines.Add(string.Empty); lines.Add($"# {lowerHyphenFullName}"); lines.Add(string.Empty); - const char father = 'F'; - const char mother = 'M'; - const string wife = "WIFE"; - const string child = "CHIL"; - const string husband = "HUSB"; - const string person = "person"; foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in genealogicalDataCommunicationRelations) { if (genealogicalDataCommunicationRelation.Relation != child) @@ -95,27 +99,28 @@ internal abstract class MarkDown lines.Add(string.Empty); hasRelation = true; } + decade = relation.NickName[..3]; if (!personKeyFormattedToPersonFullName.TryGetValue(relation.NickName, out personFullName)) lowerHyphenRelation = relation.NickName; else - lowerHyphenRelation = Regex.Replace(personFullName.ToLower(), "[^a-z0-9-]", "-"); + lowerHyphenRelation = Regex.Replace(personFullName.ToLower(), "[^a-z0-9-]", "-").Replace("--", "-"); if (string.IsNullOrEmpty(genealogicalDataCommunicationRelation.LineTwo)) - lines.Add($"- [[{person}/{lowerHyphenRelation}]]"); + lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]]"); else { if (genealogicalDataCommunicationRelation.LineTwo[1] == father) { if (relation.Relation == wife) - lines.Add($"- [[{person}/{lowerHyphenRelation}]] {nameof(mother)}"); + lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]] {nameof(mother)}"); else if (relation.Relation == husband) - lines.Add($"- [[{person}/{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(father)}"); + lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(father)}"); } else if (genealogicalDataCommunicationRelation.LineTwo[1] == mother) { if (relation.Relation == husband) - lines.Add($"- [[{person}/{lowerHyphenRelation}]] {nameof(father)}"); + lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]] {nameof(father)}"); else if (relation.Relation == wife) - lines.Add($"- [[{person}/{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(mother)}"); + lines.Add($"- [[{person}/{decade}/{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(mother)}"); } } } @@ -124,7 +129,7 @@ internal abstract class MarkDown if (hasRelation) lines.Add(string.Empty); string text = string.Join(Environment.NewLine, lines); - string directory = Path.Combine(a2PeopleContentDirectory, $"content-{ticks}", person); + string directory = Path.Combine(a2PeopleContentDirectory, $"content-{ticks}", person, personKeyFormatted[..3]); if (!Directory.Exists(directory)) _ = Directory.CreateDirectory(directory); _ = IPath.WriteAllText(Path.Combine(directory, $"{lowerHyphenFullName}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true); diff --git a/Shared/Models/Stateless/Methods/PersonContainer.cs b/Shared/Models/Stateless/Methods/PersonContainer.cs index a3d1e7f..e810a5d 100644 --- a/Shared/Models/Stateless/Methods/PersonContainer.cs +++ b/Shared/Models/Stateless/Methods/PersonContainer.cs @@ -1,5 +1,4 @@ using System.Collections.ObjectModel; -using System.Text.RegularExpressions; namespace View_by_Distance.Shared.Models.Stateless.Methods; @@ -395,15 +394,12 @@ internal abstract class PersonContainer { bool? male; bool? first; - string fullName; string[] matches; string? directory; bool isDefaultName; bool verify = true; const int zero = 0; string personKeyFormatted; - string lowerHyphenFullName; - List distinct = new(); Models.GenealogicalDataCommunication genealogicalDataCommunication; GenealogicalDataCommunicationLines? genealogicalDataCommunicationLines; ReadOnlyDictionary personKeyFormattedToPersonFullName = GetPersonKeyFormattedToPersonFullName(personBirthdayFormat, personContainers); @@ -433,12 +429,7 @@ internal abstract class PersonContainer if (genealogicalDataCommunication.Death is null && personContainer.PersonDirectory.Status == 'D' || genealogicalDataCommunication.Death is not null && personContainer.PersonDirectory.Status == 'A') continue; GenealogicalDataCommunication.WriteFile(personKeyFormatted, personContainer.Person.Name, personContainer.GenealogicalDataCommunicationRelationIndividualsLines, isDefaultName, directory, genealogicalDataCommunication, verify, first.Value); - fullName = PersonName.GetFullName(personContainer.Person.Name); - lowerHyphenFullName = $"{Regex.Replace(fullName.ToLower(), "[^a-z0-9-]", "-")}"; - if (distinct.Contains(lowerHyphenFullName)) - continue; - MarkDown.WriteFile(personKeyFormatted, ticks, personContainer.Person.Name, genealogicalDataCommunicationRelations, a2PeopleContentDirectory, personKeyFormattedToPersonFullName, familyIndexToCollection, isDefaultName, genealogicalDataCommunication, first.Value, fullName, lowerHyphenFullName); - distinct.Add(lowerHyphenFullName); + MarkDown.WriteFile(personKeyFormatted, ticks, personContainer.Person.Name, genealogicalDataCommunicationRelations, a2PeopleContentDirectory, personKeyFormattedToPersonFullName, familyIndexToCollection, isDefaultName, genealogicalDataCommunication, first.Value); } }