ConvertFrontMatterToJsonFriendly

This commit is contained in:
2023-07-21 14:42:24 -07:00
parent d6266139f8
commit d22f2a9808
14 changed files with 228 additions and 75 deletions

View File

@ -1,10 +1,10 @@
--- ---
created: 2023-07-08T00:27:35.865Z created: "2023-07-21T21:06:45.447Z"
updated: 2023-07-08T03:13:43.907Z updated: "2023-07-21T21:06:45.448Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: [] completed: "2023-07-08T03:13:43.907Z"
completed: 2023-07-08T03:13:43.907Z type: "note"
--- ---
# Add / Update date in Front Matter # Add / Update date in Front Matter

View File

@ -1,11 +1,11 @@
--- ---
created: 2023-07-08T00:31:18.301Z created: "2023-07-21T21:06:45.449Z"
updated: 2023-07-08T03:13:47.959Z updated: "2023-07-21T21:06:45.449Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: [] started: "2023-07-08T00:31:22.970Z"
started: 2023-07-08T00:31:22.970Z completed: "2023-07-08T03:13:47.959Z"
completed: 2023-07-08T03:13:47.959Z type: "note"
--- ---
# Break Circular References # Break Circular References

View File

@ -1,10 +1,10 @@
--- ---
created: 2023-07-08T00:31:48.068Z created: "2023-07-21T21:06:45.451Z"
updated: 2023-07-08T03:13:39.928Z updated: "2023-07-21T21:06:45.451Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: [] completed: "2023-07-08T03:13:39.928Z"
completed: 2023-07-08T03:13:39.928Z type: "note"
--- ---
# Convert files to slug name # Convert files to slug name

View File

@ -1,11 +1,11 @@
--- ---
created: 2023-07-08T00:28:50.180Z created: "2023-07-21T21:06:45.453Z"
updated: 2023-07-08T03:14:14.308Z updated: "2023-07-21T21:06:45.453Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: [] started: "2023-07-08T02:17:20.346Z"
started: 2023-07-08T02:17:20.346Z completed: "2023-07-08T03:14:14.308Z"
completed: 2023-07-08T03:14:14.308Z type: "note"
--- ---
# Convert Wiki Links to Markdown Links # Convert Wiki Links to Markdown Links

View File

@ -1,10 +1,10 @@
--- ---
created: 2023-07-08T00:30:27.277Z created: "2023-07-21T21:06:45.455Z"
updated: 2023-07-08T04:49:18.108Z updated: "2023-07-21T21:06:45.456Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: [] started: "2023-07-08T04:41:56.433Z"
started: 2023-07-08T04:41:56.433Z type: "note"
--- ---
# Find orphan links # Find orphan links

View File

@ -1,10 +1,9 @@
--- ---
type: "kanbn" type: "kanbn"
created: 2023-07-18T14:53:27.412Z created: "2023-07-21T21:06:45.457Z"
updated: 2023-07-18T14:53:33.147Z updated: "2023-07-21T21:06:45.457Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: []
--- ---
# Markdown links to json # Markdown links to json

View File

@ -1,10 +1,9 @@
--- ---
type: "kanbn" type: "kanbn"
created: 2023-07-18T14:48:18.667Z created: "2023-07-21T21:06:45.459Z"
updated: 2023-07-18T14:48:18.660Z updated: "2023-07-21T21:06:45.459Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: []
--- ---
# Markdown to json # Markdown to json

View File

@ -1,11 +1,11 @@
--- ---
created: 2023-07-08T00:30:00.353Z created: "2023-07-21T21:06:45.460Z"
updated: 2023-07-08T04:08:04.155Z updated: "2023-07-21T21:06:45.461Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: [] started: "2023-07-08T02:17:23.556Z"
started: 2023-07-08T02:17:23.556Z completed: "2023-07-08T04:08:04.156Z"
completed: 2023-07-08T04:08:04.156Z type: "note"
--- ---
# Populate a collection of FileInfo, Front Matter and First # indent of 1 # Populate a collection of FileInfo, Front Matter and First # indent of 1

View File

@ -1,11 +1,10 @@
--- ---
type: kanbn type: "kanbn"
created: 2023-07-18T14:50:28.239Z created: "2023-07-21T21:06:45.462Z"
updated: 2023-07-19T04:46:32.554Z updated: "2023-07-21T21:06:45.462Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: [] completed: "2023-07-19T04:40:41.523Z"
completed: 2023-07-19T04:40:41.523Z
--- ---
# Relative Path to relative to content # Relative Path to relative to content

View File

@ -1,10 +1,10 @@
--- ---
created: 2023-07-08T03:22:14.065Z created: "2023-07-21T21:06:45.465Z"
updated: 2023-07-08T04:08:05.706Z updated: "2023-07-21T21:06:45.465Z"
assigned: "" assigned: ""
progress: 0 progress: 0
tags: [] completed: "2023-07-08T04:08:05.706Z"
completed: 2023-07-08T04:08:05.706Z type: "note"
--- ---
# Use humanizer on title of links # Use humanizer on title of links

View File

@ -246,11 +246,11 @@ internal static partial class HelperCreateNoteFiles
file = Path.Combine(destinationDirectory, $"{fileName}.md"); file = Path.Combine(destinationDirectory, $"{fileName}.md");
allLines.Clear(); allLines.Clear();
allLines.Add("---"); allLines.Add("---");
allLines.Add($"type: '{type}'"); allLines.Add($"type: \"{type}\"");
allLines.Add($"title: '{title}'"); allLines.Add($"title: \"{title}\"");
allLines.Add($"description: '{columns[descriptionKey].Trim()}'"); allLines.Add($"description: \"{columns[descriptionKey].Trim()}\"");
allLines.Add($"created: {dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}"); allLines.Add($"created: \"{dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}\"");
allLines.Add($"updated: {dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}"); allLines.Add($"updated: \"{dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}\"");
if (!string.IsNullOrEmpty(tags)) if (!string.IsNullOrEmpty(tags))
allLines.Add(tags); allLines.Add(tags);
if (!string.IsNullOrEmpty(attributes)) if (!string.IsNullOrEmpty(attributes))

View File

@ -58,15 +58,15 @@ internal static class HelperKanbanMetadata
{ {
if (itemLineNumber == 0) if (itemLineNumber == 0)
throw new NotSupportedException(); throw new NotSupportedException();
(lines, lineNumber) = HelperMarkdown.GetStatusAndMetaEndLineNumbers(fileInfo); (lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(fileInfo);
if (!lines.Any()) if (!lines.Any())
continue; continue;
statusLine = $"status: \"{groupCount}-{group}\""; statusLine = $"status: \"{groupCount}-{group}\"";
indexFileLines[itemLineNumber] = $"{fileInfo.LastWriteTime.Ticks}~~~{indexFileLines[itemLineNumber]}"; indexFileLines[itemLineNumber] = $"{fileInfo.LastWriteTime.Ticks}~~~{indexFileLines[itemLineNumber]}";
if (lineNumber.MetaEnd is null) if (lineNumber.FrontMatterYamlEnd is null)
throw new NotSupportedException($"{nameof(SetMetadata)} must be executed first!"); throw new NotSupportedException($"{nameof(SetMetadata)} must be executed first!");
if (lineNumber.Status is null) if (lineNumber.Status is null)
lines.Insert(lineNumber.MetaEnd.Value, statusLine); lines.Insert(lineNumber.FrontMatterYamlEnd.Value, statusLine);
else else
{ {
if (lines[lineNumber.Status.Value] == statusLine) if (lines[lineNumber.Status.Value] == statusLine)

View File

@ -2,6 +2,7 @@ using File_Folder_Helper.Models;
using Microsoft.Extensions.Logging; using Microsoft.Extensions.Logging;
using System.Text; using System.Text;
using System.Text.Json; using System.Text.Json;
using System.Text.Json.Serialization;
namespace File_Folder_Helper.Helpers; namespace File_Folder_Helper.Helpers;
@ -12,6 +13,12 @@ internal static partial class HelperMarkdown
string? StartAt, string? StartAt,
string? Destination); string? Destination);
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
[JsonSerializable(typeof(Dictionary<string, JsonElement>))]
internal partial class DictionaryStringAndJsonElementSourceGenerationContext : JsonSerializerContext
{
}
/// <summary> /// <summary>
/// Determines files text file's encoding by analyzing its byte order mark (BOM). /// Determines files text file's encoding by analyzing its byte order mark (BOM).
/// Defaults to ASCII when detection of the text file's endianness fails. /// Defaults to ASCII when detection of the text file's endianness fails.
@ -63,7 +70,7 @@ internal static partial class HelperMarkdown
return (type, h1FromFile); return (type, h1FromFile);
} }
internal static (List<string>, LineNumber) GetStatusAndMetaEndLineNumbers(FileInfo fileInfo) internal static (List<string>, LineNumber) GetStatusAndFrontMatterYamlEndLineNumbers(FileInfo fileInfo)
{ {
string line; string line;
int? h1LineNumber = null; int? h1LineNumber = null;
@ -71,7 +78,7 @@ internal static partial class HelperMarkdown
int? statusLineNumber = null; int? statusLineNumber = null;
int? createdLineNumber = null; int? createdLineNumber = null;
int? updatedLineNumber = null; int? updatedLineNumber = null;
int? metaEndLineNumber = null; int? frontMatterYamlEndLineNumber = null;
Encoding? encoding = GetEncoding(fileInfo.FullName) ?? Encoding.Default; Encoding? encoding = GetEncoding(fileInfo.FullName) ?? Encoding.Default;
string[] lines = File.ReadAllLines(fileInfo.FullName, encoding); string[] lines = File.ReadAllLines(fileInfo.FullName, encoding);
for (int i = 1; i < lines.Length; i++) for (int i = 1; i < lines.Length; i++)
@ -81,7 +88,7 @@ internal static partial class HelperMarkdown
continue; continue;
if (line[..3] == "---") if (line[..3] == "---")
{ {
metaEndLineNumber = i; frontMatterYamlEndLineNumber = i;
continue; continue;
} }
if (line.Length > 6 && line[..6] == "type: ") if (line.Length > 6 && line[..6] == "type: ")
@ -112,7 +119,7 @@ internal static partial class HelperMarkdown
} }
LineNumber lineNumber = new(createdLineNumber, LineNumber lineNumber = new(createdLineNumber,
h1LineNumber, h1LineNumber,
metaEndLineNumber, frontMatterYamlEndLineNumber,
statusLineNumber, statusLineNumber,
typeLineNumber, typeLineNumber,
updatedLineNumber); updatedLineNumber);
@ -134,15 +141,15 @@ internal static partial class HelperMarkdown
fileInfo = new(file); fileInfo = new(file);
if (fileInfo.DirectoryName is null) if (fileInfo.DirectoryName is null)
continue; continue;
(lines, lineNumber) = GetStatusAndMetaEndLineNumbers(fileInfo); (lines, lineNumber) = GetStatusAndFrontMatterYamlEndLineNumbers(fileInfo);
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName); fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
h1 = fileNameWithoutExtension.ToLower().Replace("%20", "-").Replace(' ', '-'); h1 = fileNameWithoutExtension.ToLower().Replace("%20", "-").Replace(' ', '-');
if (lines.Any()) if (lines.Any())
(type, h1) = GetTypeAndH1(appSettings, h1, lines, lineNumber); (type, h1) = GetTypeAndH1(appSettings, h1, lines, lineNumber);
else else
{ {
type = "note"; type = appSettings.DefaultNoteType;
File.WriteAllLines(file, new string[] { "---", $"type: {type}", "---", string.Empty, $"# {h1}" }); File.WriteAllLines(file, new string[] { "---", $"type: \"{type}\"", "---", string.Empty, $"# {h1}" });
lines = File.ReadAllLines(file).ToList(); lines = File.ReadAllLines(file).ToList();
} }
markdownFile = new(file, fileInfo.DirectoryName, fileInfo.Name, fileNameWithoutExtension, fileInfo.Extension, fileInfo.CreationTime, fileInfo.LastWriteTime, lineNumber, type, h1); markdownFile = new(file, fileInfo.DirectoryName, fileInfo.Name, fileNameWithoutExtension, fileInfo.Extension, fileInfo.CreationTime, fileInfo.LastWriteTime, lineNumber, type, h1);
@ -177,13 +184,13 @@ internal static partial class HelperMarkdown
results.Clear(); results.Clear();
results.AddRange(lines); results.AddRange(lines);
creationDateTime = markdownFile.CreationDateTime > markdownFile.LastWriteDateTime ? markdownFile.LastWriteDateTime : markdownFile.CreationDateTime; creationDateTime = markdownFile.CreationDateTime > markdownFile.LastWriteDateTime ? markdownFile.LastWriteDateTime : markdownFile.CreationDateTime;
typeLine = $"type: {appSettings.DefaultNoteType}"; typeLine = $"type: \"{appSettings.DefaultNoteType}\"";
h1Line = $"# {markdownFile.FileNameWithoutExtension}"; h1Line = $"# {markdownFile.FileNameWithoutExtension}";
createdLineCompare = $"created: {creationDateTime.ToUniversalTime():yyyy-MM-dd}"; createdLineCompare = $"created: \"{creationDateTime.ToUniversalTime():yyyy-MM-dd}T";
createdLine = $"created: {creationDateTime.ToUniversalTime():yyyy-MM-ddTHH:mm:ss.fffZ}"; createdLine = $"created: \"{creationDateTime.ToUniversalTime():yyyy-MM-ddTHH:mm:ss.fffZ}\"";
updatedLineCompare = $"updated: {markdownFile.LastWriteDateTime.ToUniversalTime():yyyy-MM-dd}"; updatedLineCompare = $"updated: \"{markdownFile.LastWriteDateTime.ToUniversalTime():yyyy-MM-dd}T";
updatedLine = $"updated: {markdownFile.LastWriteDateTime.ToUniversalTime():yyyy-MM-ddTHH:mm:ss.fffZ}"; updatedLine = $"updated: \"{markdownFile.LastWriteDateTime.ToUniversalTime():yyyy-MM-ddTHH:mm:ss.fffZ}\"";
if (markdownFile.LineNumber.MetaEnd is null) if (markdownFile.LineNumber.FrontMatterYamlEnd is null)
{ {
if (markdownFile.LineNumber.H1 is null) if (markdownFile.LineNumber.H1 is null)
{ {
@ -201,14 +208,14 @@ internal static partial class HelperMarkdown
{ {
if (markdownFile.LineNumber.H1 is null) if (markdownFile.LineNumber.H1 is null)
{ {
results.Insert(markdownFile.LineNumber.MetaEnd.Value + 1, string.Empty); results.Insert(markdownFile.LineNumber.FrontMatterYamlEnd.Value + 1, string.Empty);
results.Insert(markdownFile.LineNumber.MetaEnd.Value + 1, h1Line); results.Insert(markdownFile.LineNumber.FrontMatterYamlEnd.Value + 1, h1Line);
results.Insert(markdownFile.LineNumber.MetaEnd.Value + 1, string.Empty); results.Insert(markdownFile.LineNumber.FrontMatterYamlEnd.Value + 1, string.Empty);
} }
if (markdownFile.LineNumber.Type is null) if (markdownFile.LineNumber.Type is null)
results.Insert(markdownFile.LineNumber.MetaEnd.Value, typeLine); results.Insert(markdownFile.LineNumber.FrontMatterYamlEnd.Value, typeLine);
if (markdownFile.LineNumber.Updated is null) if (markdownFile.LineNumber.Updated is null)
results.Insert(markdownFile.LineNumber.MetaEnd.Value, updatedLine); results.Insert(markdownFile.LineNumber.FrontMatterYamlEnd.Value, updatedLine);
else else
{ {
if (results[markdownFile.LineNumber.Updated.Value].Contains('$')) if (results[markdownFile.LineNumber.Updated.Value].Contains('$'))
@ -218,7 +225,7 @@ internal static partial class HelperMarkdown
results[markdownFile.LineNumber.Updated.Value] = updatedLine; results[markdownFile.LineNumber.Updated.Value] = updatedLine;
} }
if (markdownFile.LineNumber.Created is null) if (markdownFile.LineNumber.Created is null)
results.Insert(markdownFile.LineNumber.MetaEnd.Value, createdLine); results.Insert(markdownFile.LineNumber.FrontMatterYamlEnd.Value, createdLine);
else if (results[markdownFile.LineNumber.Created.Value][..createdLineCompare.Length] != createdLineCompare) else if (results[markdownFile.LineNumber.Created.Value][..createdLineCompare.Length] != createdLineCompare)
results[markdownFile.LineNumber.Created.Value] = createdLine; results[markdownFile.LineNumber.Created.Value] = createdLine;
} }
@ -229,6 +236,149 @@ internal static partial class HelperMarkdown
return result; return result;
} }
private static (string?, Dictionary<string, JsonElement>?, string[]) Get(int frontMatterYamlEnd, string[] lines)
{
string? result;
List<string> results = new();
Dictionary<string, JsonElement>? keyValuePairs;
string[] segments;
string[] segmentsB;
string segmentsLast;
string segmentsFirst;
List<string> jsonLines = new();
for (int i = 0; i < frontMatterYamlEnd; i++)
{
if (lines[i] == "---")
continue;
segments = lines[i].Split(": ");
if (segments.Length != 2)
{
jsonLines.Clear();
break;
}
segmentsLast = segments.Last().Trim();
segmentsFirst = segments.First().Trim();
if (string.IsNullOrEmpty(segmentsLast))
continue;
if (segmentsFirst.First() == '"' && segmentsFirst.Last() == '"')
jsonLines.Add($"{segmentsFirst}: ");
else if (segmentsFirst.First() == '\'' && segmentsFirst.Last() == '\'')
jsonLines.Add($"\"{segmentsFirst[1..^1]}\": ");
else
jsonLines.Add($"\"{segmentsFirst}\": ");
if (segmentsLast == "[]")
jsonLines.RemoveAt(jsonLines.Count - 1);
else if (segmentsLast.First() == '"' && segmentsLast.Last() == '"')
jsonLines.Add($"{segmentsLast},");
else if (segmentsLast.First() == '"' && segmentsLast.Last() == '"')
jsonLines.Add($"\"{segmentsLast[1..^1]}\"");
else if (!segmentsLast.Contains('"') && !segmentsLast.Contains('\''))
{
if (segmentsLast is "true" or "false")
jsonLines.Add($"{segmentsLast},");
else if (DateTime.TryParse(segmentsLast, out DateTime dateTime))
jsonLines.Add($"\"{segmentsLast}\",");
else if (segmentsLast.All(l => char.IsNumber(l)))
jsonLines.Add($"{segmentsLast},");
else
{
segmentsB = segmentsLast.Split('.');
if (segmentsB.Length == 2 && segmentsB.First().Length < 7 && segmentsB.Last().Length < 7 && segmentsB.First().All(l => char.IsNumber(l)) && segmentsB.Last().All(l => char.IsNumber(l)))
jsonLines.Add($"{segmentsLast},");
else if (!segmentsLast.Contains('[') && !segmentsLast.Contains('{'))
jsonLines.Add($"\"{segmentsLast}\",");
else
{
jsonLines.Clear();
break;
}
}
}
else
{
jsonLines.Clear();
break;
}
}
if (!jsonLines.Any())
(result, keyValuePairs) = (null, null);
else
{
string afterTrim;
string jsonLinesLast = jsonLines.Last();
jsonLines.RemoveAt(jsonLines.Count - 1);
jsonLines.Add(jsonLinesLast[..^1]);
jsonLines.Insert(0, "{");
jsonLines.Add("}");
result = string.Join(Environment.NewLine, jsonLines);
keyValuePairs = JsonSerializer.Deserialize(result, DictionaryStringAndJsonElementSourceGenerationContext.Default.DictionaryStringJsonElement);
if (keyValuePairs is null)
throw new NullReferenceException(nameof(keyValuePairs));
result = JsonSerializer.Serialize(keyValuePairs, DictionaryStringAndJsonElementSourceGenerationContext.Default.DictionaryStringJsonElement);
jsonLines = result.Split(Environment.NewLine).ToList();
foreach (string jsonLine in jsonLines)
{
afterTrim = jsonLine.Trim();
if (string.IsNullOrEmpty(afterTrim) || afterTrim.First() is '{' or '}')
continue;
segments = afterTrim.Split(": ");
if (segments.Length != 2)
{
result = null;
results.Clear();
keyValuePairs = null;
break;
}
if (afterTrim[^1] != ',')
results.Add(afterTrim[1..].Replace("\": ", ": "));
else
results.Add(afterTrim[1..^1].Replace("\": ", ": "));
}
}
return (result, keyValuePairs, results.ToArray());
}
private static int ConvertFrontMatterToJsonFriendly(List<(MarkdownFile, string[])> collection)
{
int result = 0;
bool write;
List<string> results = new();
string[] frontMatterYamlLines;
foreach ((MarkdownFile markdownFile, string[] lines) in collection)
{
if (!lines.Any())
continue;
results.Clear();
if (markdownFile.LineNumber.FrontMatterYamlEnd is null)
continue;
(_, _, frontMatterYamlLines) = Get(markdownFile.LineNumber.FrontMatterYamlEnd.Value, lines);
if (!frontMatterYamlLines.Any())
continue;
results.Add("---");
results.AddRange(frontMatterYamlLines);
results.Add("---");
for (int i = markdownFile.LineNumber.FrontMatterYamlEnd.Value + 1; i < lines.Length; i++)
results.Add(lines[i]);
if (results.Count == lines.Length)
{
write = false;
for (int i = 0; i < lines.Length; i++)
{
if (results[i] == lines[i])
continue;
write = true;
break;
}
if (!write)
continue;
}
File.WriteAllLines(markdownFile.File, results);
File.SetLastWriteTime(markdownFile.File, markdownFile.LastWriteDateTime);
result += 1;
}
return result;
}
private static int CircularReference(ILogger<Worker> logger, List<(MarkdownFile, string[])> collection) private static int CircularReference(ILogger<Worker> logger, List<(MarkdownFile, string[])> collection)
{ {
int result = 0; int result = 0;
@ -237,7 +387,7 @@ internal static partial class HelperMarkdown
bool circularReference; bool circularReference;
foreach ((MarkdownFile markdownFile, string[] lines) in collection) foreach ((MarkdownFile markdownFile, string[] lines) in collection)
{ {
if (lines.Length < 1) if (!lines.Any())
continue; continue;
circularReference = false; circularReference = false;
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < lines.Length; i++)
@ -294,7 +444,7 @@ internal static partial class HelperMarkdown
string check; string check;
foreach ((MarkdownFile markdownFile, string[] lines) in collection) foreach ((MarkdownFile markdownFile, string[] lines) in collection)
{ {
if (lines.Length < 1) if (!lines.Any())
continue; continue;
found = false; found = false;
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < lines.Length; i++)
@ -501,7 +651,7 @@ internal static partial class HelperMarkdown
Dictionary<string, List<MarkdownFile>> keyValuePairs = record.StartAt is null ? GetKeyValuePairs(collection) : GetKeyValuePairs(appSettings, record); Dictionary<string, List<MarkdownFile>> keyValuePairs = record.StartAt is null ? GetKeyValuePairs(collection) : GetKeyValuePairs(appSettings, record);
foreach ((MarkdownFile markdownFile, string[] lines) in collection) foreach ((MarkdownFile markdownFile, string[] lines) in collection)
{ {
if (lines.Length < 1) if (!lines.Any())
continue; continue;
write = false; write = false;
for (int i = 0; i < lines.Length; i++) for (int i = 0; i < lines.Length; i++)
@ -748,7 +898,7 @@ internal static partial class HelperMarkdown
{ {
string? root = Path.GetPathRoot(destination); string? root = Path.GetPathRoot(destination);
if (root is null || !Directory.Exists(root)) if (root is null || !Directory.Exists(root))
throw new NotSupportedException($"This method requires a valid -d path <{root}>!"); throw new NotSupportedException($"This method requires frontMatterYamlLines valid -d path <{root}>!");
if (!Directory.Exists(destination)) if (!Directory.Exists(destination))
_ = Directory.CreateDirectory(destination); _ = Directory.CreateDirectory(destination);
} }
@ -768,6 +918,12 @@ internal static partial class HelperMarkdown
collection = GetCollection(appSettings, GetFiles(appSettings, record)); collection = GetCollection(appSettings, GetFiles(appSettings, record));
logger.LogInformation("{updated} Markdown file(s) were updated", updated); logger.LogInformation("{updated} Markdown file(s) were updated", updated);
} }
updated = ConvertFrontMatterToJsonFriendly(collection);
if (updated != 0)
{
collection = GetCollection(appSettings, GetFiles(appSettings, record));
logger.LogInformation("{updated} Markdown file(s) were updated", updated);
}
updated = CircularReference(logger, collection); updated = CircularReference(logger, collection);
if (updated != 0) if (updated != 0)
{ {
@ -884,7 +1040,7 @@ internal static partial class HelperMarkdown
{ {
Record record = GetRecord(args); Record record = GetRecord(args);
if (string.IsNullOrEmpty(record.Destination)) if (string.IsNullOrEmpty(record.Destination))
throw new NotSupportedException("This method requires a -d path!"); throw new NotSupportedException("This method requires frontMatterYamlLines -d path!");
List<(string, string, string[])> collection = GetWithLinksForHugo(appSettings, record); List<(string, string, string[])> collection = GetWithLinksForHugo(appSettings, record);
if (!collection.Any()) if (!collection.Any())
logger.LogInformation("No files?"); logger.LogInformation("No files?");

View File

@ -4,7 +4,7 @@ namespace File_Folder_Helper.Helpers;
public record LineNumber(int? Created, public record LineNumber(int? Created,
int? H1, int? H1,
int? MetaEnd, int? FrontMatterYamlEnd,
int? Status, int? Status,
int? Type, int? Type,
int? Updated); int? Updated);