From a154662b9aa81ac8afecb62bcb4137697959a40f Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Mon, 17 Jul 2023 01:09:52 -0700 Subject: [PATCH] Family Tree as Markdown Files - Hugo --- .kanbn/tasks/family-tree-as-markdown-files.md | 26 ++++++++++++- Instance/DlibDotNet.cs | 2 +- .../Stateless/Methods/IPersonContainer.cs | 8 ++-- Shared/Models/Stateless/Methods/MarkDown.cs | 37 ++++++++++--------- .../Stateless/Methods/PersonContainer.cs | 4 +- 5 files changed, 51 insertions(+), 26 deletions(-) diff --git a/.kanbn/tasks/family-tree-as-markdown-files.md b/.kanbn/tasks/family-tree-as-markdown-files.md index 81bbac3..1f02c71 100644 --- a/.kanbn/tasks/family-tree-as-markdown-files.md +++ b/.kanbn/tasks/family-tree-as-markdown-files.md @@ -9,4 +9,28 @@ tags: [] # Family Tree as Markdown Files - [ ] Look at how I can export from ged files -- [x] In addition to writing the *.pged maybe write *.md also +- [x] In addition to writing the _.pged maybe write _.md also +- [x] Host hugo + +- [hugo-obsidian](https://github.com/jackyzha0/hugo-obsidian) + +```bash +l: +cd git +git clone https://github.com/jackyzha0/hugo-obsidian.git +cd hugo-obsidian +go build +``` + +- [quartz](https://github.com/jackyzha0/quartz) + +```bash +l: +cd git +git clone https://github.com/jackyzha0/quartz.git +cd quartz +code-insiders . +hugo-obsidian -input=content -output=assets/indices -index -root=. +hugo server --enableGitInfo --minify +hugo server --buildDrafts +``` diff --git a/Instance/DlibDotNet.cs b/Instance/DlibDotNet.cs index 646a2d0..4f5b6e0 100644 --- a/Instance/DlibDotNet.cs +++ b/Instance/DlibDotNet.cs @@ -131,7 +131,7 @@ public partial class DlibDotNet TimeSpan a2LastWriteTimeTimeSpan = new(ticks - new DirectoryInfo(a2PeopleContentDirectory).LastWriteTime.Ticks); if (a2LastWriteTimeTimeSpan.TotalDays > 1) { - IPersonContainer.MaybeWriteFiles(configuration.MappingDefaultName, configuration.PersonBirthdayFormat, genealogicalDataCommunicationRelations, _PersonContainers); + IPersonContainer.MaybeWriteFiles(configuration.MappingDefaultName, configuration.PersonBirthdayFormat, ticks, genealogicalDataCommunicationRelations, _PersonContainers, a2PeopleContentDirectory); if (IGenealogicalDataCommunication.CleanDisplayDirectoryAllFilesAndWriteTicksGed(_Configuration.MappingDefaultName, _Configuration.PersonBirthdayFormat, _PersonContainers, headerLines, familyGroupLines, footerLines, ticks, a2PeopleContentDirectory)) _PersonContainers = IPersonContainer.GetPersonContainers(storage, configuration.MappingDefaultName, configuration.PersonBirthdayFormat, configuration.PersonCharacters.ToArray(), _Faces.FileNameExtension, individuals); } diff --git a/Shared/Models/Stateless/Methods/IPersonContainer.cs b/Shared/Models/Stateless/Methods/IPersonContainer.cs index 90bc173..fa28e8a 100644 --- a/Shared/Models/Stateless/Methods/IPersonContainer.cs +++ b/Shared/Models/Stateless/Methods/IPersonContainer.cs @@ -22,10 +22,10 @@ public interface IPersonContainer static List GetPersonContainers(Properties.IStorage storage, string mappingDefaultName, string personBirthdayFormat, char[] personCharacters, string facesFileNameExtension, ReadOnlyDictionary individuals) => PersonContainer.GetPersonContainers(storage, mappingDefaultName, personBirthdayFormat, personCharacters, facesFileNameExtension, individuals); - void TestStatic_MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, List genealogicalDataCommunicationRelations, List personContainers) => - MaybeWriteFiles(mappingDefaultName, personBirthdayFormat, genealogicalDataCommunicationRelations, personContainers); - static void MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, List genealogicalDataCommunicationRelations, List personContainers) => - PersonContainer.MaybeWriteFiles(mappingDefaultName, personBirthdayFormat, genealogicalDataCommunicationRelations, personContainers); + void TestStatic_MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List genealogicalDataCommunicationRelations, List personContainers, string a2PeopleContentDirectory) => + MaybeWriteFiles(mappingDefaultName, personBirthdayFormat, ticks, genealogicalDataCommunicationRelations, personContainers, a2PeopleContentDirectory); + static void MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List genealogicalDataCommunicationRelations, List personContainers, string a2PeopleContentDirectory) => + PersonContainer.MaybeWriteFiles(mappingDefaultName, personBirthdayFormat, ticks, genealogicalDataCommunicationRelations, personContainers, a2PeopleContentDirectory); List<(long?, string)> TestStatic_GetDisplay(string personBirthdayFormat, Models.PersonContainer personContainer) => GetDisplay(personBirthdayFormat, personContainer); diff --git a/Shared/Models/Stateless/Methods/MarkDown.cs b/Shared/Models/Stateless/Methods/MarkDown.cs index 2074470..3f291dc 100644 --- a/Shared/Models/Stateless/Methods/MarkDown.cs +++ b/Shared/Models/Stateless/Methods/MarkDown.cs @@ -8,7 +8,7 @@ internal abstract class MarkDown // ... - internal static void WriteFile(string personKeyFormatted, Models.PersonName personName, List genealogicalDataCommunicationRelations, ReadOnlyDictionary personKeyFormattedToPersonFullName, ReadOnlyDictionary> 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 genealogicalDataCommunicationRelations, string a2PeopleContentDirectory, ReadOnlyDictionary personKeyFormattedToPersonFullName, ReadOnlyDictionary> 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 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); } } \ No newline at end of file diff --git a/Shared/Models/Stateless/Methods/PersonContainer.cs b/Shared/Models/Stateless/Methods/PersonContainer.cs index f6cbc26..a3d1e7f 100644 --- a/Shared/Models/Stateless/Methods/PersonContainer.cs +++ b/Shared/Models/Stateless/Methods/PersonContainer.cs @@ -391,7 +391,7 @@ internal abstract class PersonContainer return new(results); } - internal static void MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, List genealogicalDataCommunicationRelations, List personContainers) + internal static void MaybeWriteFiles(string mappingDefaultName, string personBirthdayFormat, long ticks, List genealogicalDataCommunicationRelations, List 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); } }