Removed GenealogicalDataCommunication.WriteFile
This commit is contained in:
@ -10,74 +10,52 @@ internal abstract class MarkDown
|
||||
|
||||
// ...
|
||||
|
||||
internal static void WriteFile(string personKeyFormatted, long ticks, Models.PersonName personName, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, string a2PeopleContentDirectory, Calendar calendar, ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, bool isDefaultName, Models.GenealogicalDataCommunication genealogicalDataCommunication, bool first)
|
||||
internal static List<string> GetFrontMatter(long ticks, string fullName, string lowerHyphenFullName, Models.GenealogicalDataCommunication genealogicalDataCommunication)
|
||||
{
|
||||
List<string> results = new();
|
||||
string afterTrim;
|
||||
string[] jsonLines = genealogicalDataCommunication.ToString().Split(Environment.NewLine);
|
||||
foreach (string jsonLine in jsonLines)
|
||||
{
|
||||
afterTrim = jsonLine.Trim();
|
||||
if (afterTrim.Length < 3)
|
||||
continue;
|
||||
if (afterTrim[^1] != ',')
|
||||
results.Add(afterTrim[1..].Replace("\": \"", ": \""));
|
||||
else
|
||||
results.Add(afterTrim[1..^1].Replace("\": \"", ": \""));
|
||||
}
|
||||
if (results.Any())
|
||||
{
|
||||
DateTime dateTime = new DateTime(ticks).ToUniversalTime();
|
||||
results.Insert(0, $"updated: \"{dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}\"");
|
||||
results.Insert(0, $"created: \"{dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}\"");
|
||||
results.Insert(0, $"title: \"{fullName}\"");
|
||||
results.Insert(0, "type: \"person\"");
|
||||
results.Add("draft: false");
|
||||
results.Insert(0, "---");
|
||||
results.Add($"{nameof(lowerHyphenFullName)}: \"{lowerHyphenFullName}\"");
|
||||
results.Add("---");
|
||||
}
|
||||
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> frontMatter)
|
||||
{
|
||||
string decade;
|
||||
string jrOrSr;
|
||||
string? personFullName;
|
||||
const char father = 'F';
|
||||
const char mother = 'M';
|
||||
bool hasRelation = false;
|
||||
const string wife = "WIFE";
|
||||
List<string> lines = new();
|
||||
StringBuilder link = new();
|
||||
const string child = "CHIL";
|
||||
const string husband = "HUSB";
|
||||
const string person = "person";
|
||||
DateTime dateTime = new(ticks);
|
||||
string fullName = PersonName.GetFullName(personName);
|
||||
List<GenealogicalDataCommunicationRelation>? relations;
|
||||
string now = dateTime.ToUniversalTime().ToString("yyyy-MM-ddTHH:mm:ss.fffZ");
|
||||
string lowerHyphenFullName = $"{Regex.Replace(fullName.ToLower(), "[^a-z0-9-]", "-")}";
|
||||
string code = IPersonBirthday.GetHour(genealogicalDataCommunication.Death is null, genealogicalDataCommunication.Sex).ToString("00");
|
||||
List<string> lines = new()
|
||||
{
|
||||
"---",
|
||||
$"type: '{person}'",
|
||||
$"created: {now}",
|
||||
$"updated: {now}",
|
||||
$"draft: false",
|
||||
$"title: '{fullName}'",
|
||||
$"{nameof(lowerHyphenFullName)}: '{lowerHyphenFullName}'",
|
||||
};
|
||||
if (string.IsNullOrEmpty(personName.Alias.Value))
|
||||
jrOrSr = string.Empty;
|
||||
else
|
||||
{
|
||||
if (personName.Alias.Value.Contains(" Jr"))
|
||||
jrOrSr = " Jr";
|
||||
else if (personName.Alias.Value.Contains(" Sr"))
|
||||
jrOrSr = " Sr";
|
||||
else
|
||||
jrOrSr = string.Empty;
|
||||
}
|
||||
lines.Add($"name: '{personName.First.Value} /{personName.Last.Value}/{jrOrSr}'");
|
||||
if (first && !personKeyFormatted.EndsWith(code))
|
||||
personKeyFormatted = $"{personKeyFormatted[..^2]}{code}";
|
||||
if (!string.IsNullOrEmpty(personName.First.Value))
|
||||
lines.Add($"given: '{personName.First.Value}'");
|
||||
if (!string.IsNullOrEmpty(personName.Last.Value))
|
||||
lines.Add($"surname: '{personName.Last.Value}'");
|
||||
if (!string.IsNullOrEmpty(jrOrSr))
|
||||
lines.Add($"suffix: '{jrOrSr.Trim()}'");
|
||||
lines.Add($"sex: '{genealogicalDataCommunication.Sex}'");
|
||||
if (genealogicalDataCommunication.Birth is not null)
|
||||
{
|
||||
lines.Add($"date: {genealogicalDataCommunication.Birth.Value:yyyy-MM-ddT00:00:00.000Z}");
|
||||
Models.PersonBirthday personBirthday = new(genealogicalDataCommunication.Birth.Value);
|
||||
if (!IPersonBirthday.IsCounterPersonBirthday(personBirthday))
|
||||
lines.Add($"birthDate: '{genealogicalDataCommunication.Birth.Value:dd MMM yyyy}'");
|
||||
}
|
||||
if (genealogicalDataCommunication.Death is not null)
|
||||
{
|
||||
if (genealogicalDataCommunication?.Death is null || genealogicalDataCommunication.Death == genealogicalDataCommunication.Birth || IPersonBirthday.IsCounterPersonBirthday(new(genealogicalDataCommunication.Death.Value)))
|
||||
lines.Add("isDead: true");
|
||||
else
|
||||
lines.Add($"deathDate: '{genealogicalDataCommunication.Death.Value:dd MMM yyyy}'");
|
||||
}
|
||||
if (isDefaultName)
|
||||
lines.Add($"{nameof(isDefaultName)}: {isDefaultName}");
|
||||
lines.Add($"{nameof(personKeyFormatted)}: '{personKeyFormatted}'");
|
||||
lines.Add("---");
|
||||
lines.AddRange(frontMatter);
|
||||
lines.Add(string.Empty);
|
||||
lines.Add($"# {fullName}");
|
||||
lines.Add(string.Empty);
|
||||
@ -117,7 +95,7 @@ internal abstract class MarkDown
|
||||
if (personFullName is null)
|
||||
_ = link.Append(relation.NickName);
|
||||
else
|
||||
_ = link.Append(Regex.Replace(personFullName.ToLower(), "[^a-z0-9-]", "-").Replace("--", "-"));
|
||||
_ = link.Append(Regex.Replace(personFullName.ToLower(), pattern, "-").Replace("--", "-"));
|
||||
_ = link.Append(".md) ");
|
||||
if (string.IsNullOrEmpty(genealogicalDataCommunicationRelation.LineTwo))
|
||||
lines.Add(link.ToString());
|
||||
|
Reference in New Issue
Block a user