Family Tree as Markdown Files - Hugo
This commit is contained in:
@ -22,10 +22,10 @@ public interface IPersonContainer
|
||||
static List<Models.PersonContainer> GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension, ReadOnlyDictionary<string, string[]> individuals) =>
|
||||
PersonContainer.GetPersonContainers(storage, mappingDefaultName, personBirthdayFormat, personCharacters, facesFileNameExtension, individuals);
|
||||
|
||||
void TestStatic_MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers) =>
|
||||
MaybeWriteFiles(mappingDefaultName, personBirthdayFormat, genealogicalDataCommunicationRelations, personContainers);
|
||||
static void MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers) =>
|
||||
PersonContainer.MaybeWriteFiles(mappingDefaultName, personBirthdayFormat, genealogicalDataCommunicationRelations, personContainers);
|
||||
void TestStatic_MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers, string a2PeopleContentDirectory) =>
|
||||
MaybeWriteFiles(mappingDefaultName, personBirthdayFormat, ticks, genealogicalDataCommunicationRelations, personContainers, a2PeopleContentDirectory);
|
||||
static void MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers, string a2PeopleContentDirectory) =>
|
||||
PersonContainer.MaybeWriteFiles(mappingDefaultName, personBirthdayFormat, ticks, genealogicalDataCommunicationRelations, personContainers, a2PeopleContentDirectory);
|
||||
|
||||
List<(long?, string)> TestStatic_GetDisplay(string personBirthdayFormat, Models.PersonContainer personContainer) =>
|
||||
GetDisplay(personBirthdayFormat, personContainer);
|
||||
|
@ -8,7 +8,7 @@ internal abstract class MarkDown
|
||||
|
||||
// ...
|
||||
|
||||
internal static void WriteFile(string personKeyFormatted, Models.PersonName personName, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, bool isDefaultName, string directory, Models.GenealogicalDataCommunication genealogicalDataCommunication, bool first, string fullName, string lowerHyphenFullName)
|
||||
internal static void WriteFile(string personKeyFormatted, long ticks, Models.PersonName personName, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, string a2PeopleContentDirectory, ReadOnlyDictionary<string, string> personKeyFormattedToPersonFullName, ReadOnlyDictionary<int, List<GenealogicalDataCommunicationRelation>> familyIndexToCollection, bool isDefaultName, Models.GenealogicalDataCommunication genealogicalDataCommunication, bool first, string fullName, string lowerHyphenFullName)
|
||||
{
|
||||
string? personFullName;
|
||||
bool hasRelation = false;
|
||||
@ -28,12 +28,6 @@ internal abstract class MarkDown
|
||||
jrOrSr = string.Empty;
|
||||
}
|
||||
string code = IPersonBirthday.GetHour(genealogicalDataCommunication.Death is null, genealogicalDataCommunication.Sex).ToString("00");
|
||||
if (directory.EndsWith("00"))
|
||||
directory = string.Concat(directory[..^2], code);
|
||||
else if (directory.EndsWith("01"))
|
||||
directory = string.Concat(directory[..^2], code);
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
if (first && !personKeyFormatted.EndsWith(code))
|
||||
personKeyFormatted = $"{personKeyFormatted[..^2]}{code}";
|
||||
List<string> lines = new()
|
||||
@ -42,18 +36,21 @@ internal abstract class MarkDown
|
||||
"type: person",
|
||||
$"created: {now}",
|
||||
$"updated: {now}",
|
||||
$"{nameof(fullName)}: {fullName}",
|
||||
$"name: {personName.First.Value} /{personName.Last.Value}/{jrOrSr}",
|
||||
$"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}");
|
||||
lines.Add($"given: '{personName.First.Value}'");
|
||||
if (!string.IsNullOrEmpty(personName.Last.Value))
|
||||
lines.Add($"surname: {personName.Last.Value}");
|
||||
lines.Add($"surname: '{personName.Last.Value}'");
|
||||
if (!string.IsNullOrEmpty(jrOrSr))
|
||||
lines.Add($"suffix: {jrOrSr.Trim()}");
|
||||
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}");
|
||||
@ -77,6 +74,7 @@ internal abstract class MarkDown
|
||||
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)
|
||||
@ -102,22 +100,22 @@ internal abstract class MarkDown
|
||||
else
|
||||
lowerHyphenRelation = Regex.Replace(personFullName.ToLower(), "[^a-z0-9-]", "-");
|
||||
if (string.IsNullOrEmpty(genealogicalDataCommunicationRelation.LineTwo))
|
||||
lines.Add($"- [[{lowerHyphenRelation}]]");
|
||||
lines.Add($"- [[{person}/{lowerHyphenRelation}]]");
|
||||
else
|
||||
{
|
||||
if (genealogicalDataCommunicationRelation.LineTwo[1] == father)
|
||||
{
|
||||
if (relation.Relation == wife)
|
||||
lines.Add($"- [[{lowerHyphenRelation}]] {nameof(mother)}");
|
||||
lines.Add($"- [[{person}/{lowerHyphenRelation}]] {nameof(mother)}");
|
||||
else if (relation.Relation == husband)
|
||||
lines.Add($"- [[{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(father)}");
|
||||
lines.Add($"- [[{person}/{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(father)}");
|
||||
}
|
||||
else if (genealogicalDataCommunicationRelation.LineTwo[1] == mother)
|
||||
{
|
||||
if (relation.Relation == husband)
|
||||
lines.Add($"- [[{lowerHyphenRelation}]] {nameof(father)}");
|
||||
lines.Add($"- [[{person}/{lowerHyphenRelation}]] {nameof(father)}");
|
||||
else if (relation.Relation == wife)
|
||||
lines.Add($"- [[{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(mother)}");
|
||||
lines.Add($"- [[{person}/{lowerHyphenRelation}]] {genealogicalDataCommunicationRelation.LineTwo.Split(' ').Last()} {nameof(mother)}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -126,7 +124,10 @@ internal abstract class MarkDown
|
||||
if (hasRelation)
|
||||
lines.Add(string.Empty);
|
||||
string text = string.Join(Environment.NewLine, lines);
|
||||
_ = IPath.WriteAllText(Path.Combine(directory, $"{lowerHyphenFullName}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
string directory = Path.Combine(a2PeopleContentDirectory, $"content-{ticks}", person);
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
_ = IPath.WriteAllText(Path.Combine(directory, $"{lowerHyphenFullName}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
}
|
@ -391,7 +391,7 @@ internal abstract class PersonContainer
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static void MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers)
|
||||
internal static void MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List<GenealogicalDataCommunicationRelation> genealogicalDataCommunicationRelations, List<Models.PersonContainer> personContainers, string a2PeopleContentDirectory)
|
||||
{
|
||||
bool? male;
|
||||
bool? first;
|
||||
@ -437,7 +437,7 @@ internal abstract class PersonContainer
|
||||
lowerHyphenFullName = $"{Regex.Replace(fullName.ToLower(), "[^a-z0-9-]", "-")}";
|
||||
if (distinct.Contains(lowerHyphenFullName))
|
||||
continue;
|
||||
MarkDown.WriteFile(personKeyFormatted, personContainer.Person.Name, genealogicalDataCommunicationRelations, personKeyFormattedToPersonFullName, familyIndexToCollection, isDefaultName, directory, genealogicalDataCommunication, first.Value, fullName, lowerHyphenFullName);
|
||||
MarkDown.WriteFile(personKeyFormatted, ticks, personContainer.Person.Name, genealogicalDataCommunicationRelations, a2PeopleContentDirectory, personKeyFormattedToPersonFullName, familyIndexToCollection, isDefaultName, genealogicalDataCommunication, first.Value, fullName, lowerHyphenFullName);
|
||||
distinct.Add(lowerHyphenFullName);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user