SaveParents

Removed GetFilteredOutMapped
Removed GetNonSpecificPeopleCollection
This commit is contained in:
2023-07-26 23:34:58 -07:00
parent a18fb1e756
commit 9071784255
14 changed files with 478 additions and 338 deletions

View File

@ -33,10 +33,12 @@ internal abstract class MarkDown
{
i = j;
afterTrim = parsedLines[j].Trim();
if (afterTrim != "],")
_ = stringBuilder.Append(afterTrim);
else
if (afterTrim == "],")
_ = stringBuilder.Append(afterTrim[..^1]);
else if (afterTrim[^1] == ',')
_ = stringBuilder.Append(afterTrim).Append(' ');
else
_ = stringBuilder.Append(afterTrim);
if (afterTrim is "]" or "],")
{
results.Add(stringBuilder.ToString());
@ -60,7 +62,7 @@ internal abstract class MarkDown
{
List<string> results;
string[] parsedLines = genealogicalDataCommunication.ToString().Split(Environment.NewLine);
results = GetFrontMatterLines(parsedLines);
results = GetFrontMatterLines(parsedLines);
if (results.Any())
{
DateTime dateTime = new DateTime(ticks).ToUniversalTime();
@ -74,96 +76,80 @@ internal abstract class MarkDown
return results;
}
internal static void WriteFile(string personKeyFormatted, long ticks, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, string a2PeopleContentDirectory, Calendar calendar, string pattern, ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, Models.GenealogicalDataCommunication genealogicalDataCommunication, string fullName, string lowerHyphenFullName, List<string> frontMatterLines)
internal static void WriteFile(string personKeyFormatted, long ticks, string a2PeopleContentDirectory, Calendar calendar, string pattern, ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, Models.GenealogicalDataCommunication genealogicalDataCommunication, string fullName, string lowerHyphenFullName, List<string> frontMatterLines)
{
string text;
string decade;
string? personFullName;
const char father = 'F';
const char mother = 'M';
bool hasRelation = false;
const string wife = "WIFE";
string? mergeWithLineTwo;
List<string> lines = new();
StringBuilder link = new();
const string child = "CHIL";
const string husband = "HUSB";
const string person = "person";
DateTime dateTime = new(ticks);
List<GenealogicalDataCommunicationRelation>? relations;
List<GenealogicalDataCommunicationRelation>? genealogicalDataCommunicationRelations;
lines.Add("---");
lines.AddRange(frontMatterLines);
lines.Add("---");
lines.Add(string.Empty);
lines.Add($"# {fullName}");
lines.Add(string.Empty);
foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in genealogicalDataCommunicationRelations)
foreach (KeyValuePair<int, List<GenealogicalDataCommunicationRelation>> keyValuePair in familyIndexToCollection)
{
if (genealogicalDataCommunication?.NickName is null || genealogicalDataCommunication.NickName.Length < 4)
continue;
if (genealogicalDataCommunicationRelation.Relation != child)
continue;
if (genealogicalDataCommunicationRelation.NickName != personKeyFormatted)
continue;
if (!familyIndexToCollection.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out relations))
continue;
foreach (GenealogicalDataCommunicationRelation relation in relations)
foreach (GenealogicalDataCommunicationRelation genealogicalDataCommunicationRelation in keyValuePair.Value)
{
if (relation.FamilyIndex != genealogicalDataCommunicationRelation.FamilyIndex)
if (genealogicalDataCommunication?.NickName is null || genealogicalDataCommunication.NickName.Length < 4)
continue;
if (relation.Relation is husband or wife)
if (genealogicalDataCommunicationRelation.Relation != IGenealogicalDataCommunication.Child)
continue;
if (genealogicalDataCommunicationRelation.NickName != personKeyFormatted)
continue;
if (!familyIndexToCollection.TryGetValue(genealogicalDataCommunicationRelation.FamilyIndex, out genealogicalDataCommunicationRelations))
continue;
foreach (GenealogicalDataCommunicationRelation relation in genealogicalDataCommunicationRelations)
{
if (!hasRelation)
if (relation.FamilyIndex != genealogicalDataCommunicationRelation.FamilyIndex)
continue;
if (relation.Relation is IGenealogicalDataCommunication.Husband or IGenealogicalDataCommunication.Wife)
{
lines.Add("## Relations");
lines.Add(string.Empty);
hasRelation = true;
}
decade = relation.NickName[..3];
_ = link.Clear();
_ = link.Append("- [");
if (!personKeyFormattedToPersonFullName.TryGetValue(relation.NickName, out personFullName))
_ = link.Append(relation.NickName);
else
_ = 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(), pattern, "-").Replace("--", "-"));
_ = link.Append(".md) ");
if (string.IsNullOrEmpty(genealogicalDataCommunicationRelation.LineTwo))
lines.Add(link.ToString());
else
{
if (genealogicalDataCommunicationRelation.LineTwo[1] == father)
if (!hasRelation)
{
if (relation.Relation == wife)
_ = link.Append(nameof(mother));
else if (relation.Relation == husband)
_ = link.Append(genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()).Append(nameof(father));
lines.Add("## Relations");
lines.Add(string.Empty);
hasRelation = true;
}
else if (genealogicalDataCommunicationRelation.LineTwo[1] == mother)
{
if (relation.Relation == husband)
_ = link.Append(nameof(father));
else if (relation.Relation == wife)
_ = link.Append(genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()).Append(nameof(mother));
}
lines.Add(link.ToString());
decade = relation.NickName[..3];
_ = link.Clear();
_ = link.Append("- [");
if (!personKeyFormattedToPersonFullName.TryGetValue(relation.NickName, out personFullName))
_ = link.Append(relation.NickName);
else
_ = 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(), pattern, "-").Replace("--", "-"));
_ = link.Append(".md) ");
mergeWithLineTwo = GenealogicalDataCommunication.GetMergeWithLineTwo(genealogicalDataCommunicationRelation, relation);
lines.Add($"{link}{mergeWithLineTwo}");
}
}
}
}
if (hasRelation)
lines.Add(string.Empty);
string text = string.Join(Environment.NewLine, lines);
// text = string.Join(Environment.NewLine, lines);
// _ = IPath.WriteAllText(Path.Combine(directory, $"{personKeyFormatted}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true);
string weekOfYear = calendar.GetWeekOfYear(dateTime, CalendarWeekRule.FirstDay, DayOfWeek.Sunday).ToString("00");
string directory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-Markdown", $"{dateTime.Year}-Week-{weekOfYear}", ticks.ToString(), person, personKeyFormatted[..3]);
if (!Directory.Exists(directory))
_ = Directory.CreateDirectory(directory);
_ = IPath.WriteAllText(Path.Combine(directory, $"{lowerHyphenFullName}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true);
string markdownOnlyDirectory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-Markdown", $"{dateTime.Year}-Week-{weekOfYear}", ticks.ToString(), person, personKeyFormatted[..3]);
if (!Directory.Exists(markdownOnlyDirectory))
_ = Directory.CreateDirectory(markdownOnlyDirectory);
text = string.Join(Environment.NewLine, lines);
_ = IPath.WriteAllText(Path.Combine(markdownOnlyDirectory, $"{lowerHyphenFullName}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true);
}
}