allFrontMatterLines
This commit is contained in:
@ -1,5 +1,7 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Globalization;
|
||||
using System.Text.Json;
|
||||
using System.Text.Json.Serialization;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace View_by_Distance.Shared.Models.Stateless.Methods;
|
||||
@ -396,17 +398,20 @@ internal abstract class PersonContainer
|
||||
{
|
||||
bool? male;
|
||||
bool? first;
|
||||
string json;
|
||||
string fullName;
|
||||
string[] matches;
|
||||
string[] segments;
|
||||
string? directory;
|
||||
bool isDefaultName;
|
||||
const int zero = 0;
|
||||
List<string> frontMatter;
|
||||
string personKeyFormatted;
|
||||
string frontMatterLastLine;
|
||||
string lowerHyphenFullName;
|
||||
List<string> frontMatterLines;
|
||||
string pattern = "[^a-z0-9-]";
|
||||
DateTime dateTime = new(ticks);
|
||||
List<string> allFrontMatter = new();
|
||||
List<string> allFrontMatterLines = new();
|
||||
Calendar calendar = new CultureInfo("en-US").Calendar;
|
||||
Models.GenealogicalDataCommunication genealogicalDataCommunication;
|
||||
GenealogicalDataCommunicationLines? genealogicalDataCommunicationLines;
|
||||
@ -441,17 +446,36 @@ internal abstract class PersonContainer
|
||||
continue;
|
||||
fullName = PersonName.GetFullName(personContainer.Person.Name);
|
||||
lowerHyphenFullName = $"{Regex.Replace(fullName.ToLower(), pattern, "-")}";
|
||||
frontMatter = MarkDown.GetFrontMatter(ticks, fullName, lowerHyphenFullName, genealogicalDataCommunication);
|
||||
if (!frontMatter.Any())
|
||||
frontMatterLines = MarkDown.GetFrontMatterLines(ticks, fullName, lowerHyphenFullName, genealogicalDataCommunication);
|
||||
if (!frontMatterLines.Any())
|
||||
continue;
|
||||
allFrontMatter.AddRange(frontMatter);
|
||||
MarkDown.WriteFile(personKeyFormatted, ticks, genealogicalDataCommunicationRelations, a2PeopleContentDirectory, calendar, pattern, personKeyFormattedToPersonFullName, familyIndexToCollection, genealogicalDataCommunication, fullName, lowerHyphenFullName, frontMatter);
|
||||
allFrontMatterLines.Add("{");
|
||||
frontMatterLastLine = frontMatterLines.Last();
|
||||
foreach (string frontMatterLine in frontMatterLines)
|
||||
{
|
||||
segments = frontMatterLine.Split(": ");
|
||||
if (segments.Length != 2)
|
||||
continue;
|
||||
if (frontMatterLine == frontMatterLastLine)
|
||||
allFrontMatterLines.Add($"\"{string.Join("\": ", segments)}");
|
||||
else
|
||||
allFrontMatterLines.Add($"\"{string.Join("\": ", segments)},");
|
||||
}
|
||||
allFrontMatterLines.Add("},");
|
||||
MarkDown.WriteFile(personKeyFormatted, ticks, genealogicalDataCommunicationRelations, a2PeopleContentDirectory, calendar, pattern, personKeyFormattedToPersonFullName, familyIndexToCollection, genealogicalDataCommunication, fullName, lowerHyphenFullName, frontMatterLines);
|
||||
}
|
||||
if (allFrontMatterLines.Any())
|
||||
{
|
||||
directory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-Markdown", $"{dateTime.Year}-Week-{weekOfYear}", ticks.ToString());
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
json = $"[{string.Join(Environment.NewLine, allFrontMatterLines.ToArray(), 0, allFrontMatterLines.Count - 1)}{allFrontMatterLines.Last()[..^1]}]";
|
||||
Models.GenealogicalDataCommunication[]? genealogicalDataCommunications = JsonSerializer.Deserialize<Models.GenealogicalDataCommunication[]>(json);
|
||||
if (genealogicalDataCommunications is null)
|
||||
throw new NullReferenceException(nameof(genealogicalDataCommunications));
|
||||
json = JsonSerializer.Serialize(genealogicalDataCommunications, new JsonSerializerOptions { WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull });
|
||||
_ = IPath.WriteAllText(Path.Combine(directory, $"{ticks}.json"), json, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
directory = Path.Combine(a2PeopleContentDirectory, $"{dateTime.Year}-Markdown", $"{dateTime.Year}-Week-{weekOfYear}", ticks.ToString());
|
||||
if (!Directory.Exists(directory))
|
||||
_ = Directory.CreateDirectory(directory);
|
||||
string text = string.Join(Environment.NewLine, allFrontMatter);
|
||||
_ = IPath.WriteAllText(Path.Combine(directory, $"{ticks}.md"), text, updateDateWhenMatches: false, compareBeforeWrite: true);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user