1 Commits

Author SHA1 Message Date
89fdf06187 Update Markdown Helper to write json files for tables and yaml 2025-06-23 11:22:58 -07:00
2 changed files with 12 additions and 42 deletions

4
.vscode/launch.json vendored
View File

@ -13,9 +13,9 @@
"args": [
"s",
"M",
"D:/5-Other-Small/Notes/EC-Documentation",
"D:/5-Other-Small/Notes/Infineon",
"-d",
"D:/5-Other-Small/Notes/EC-Documentation/.vscode/helper",
"D:/5-Other-Small/Notes/Infineon/.vscode/helper",
"s",
"X",
"D:/5-Other-Small/Proxmox/DiskInfo",

View File

@ -1271,17 +1271,12 @@ internal static partial class HelperMarkdown
{
if (string.IsNullOrEmpty(input.Destination))
throw new NotSupportedException();
string old;
string json;
string[] lines;
string fileName;
List<Block> blocks;
string directoryName;
List<string>? jsonLines;
MarkdownFile markdownFile;
List<string> fileNames = [];
ReadOnlyCollection<Table> tables;
Dictionary<string, List<string>> results = [];
ReadOnlyCollection<Block> javaScriptObjectNotationBlocks;
ReadOnlyCollection<Block> yetAnotherMarkupLanguageBlocks;
ReadOnlyDictionary<string, MarkdownFileAndLines> relativeToCollection = GetRelativeToCollection(appSettings, input, gitOthersModifiedAndDeletedExcludingStandardFiles: null);
@ -1314,26 +1309,7 @@ internal static partial class HelperMarkdown
blocks.AddRange(GetBlocks(logger, markdownFile, yetAnotherMarkupLanguageBlocks));
if (blocks.Count == 0)
continue;
directoryName = Path.GetFileName(Path.Combine(input.Destination, markdownFile.Directory));
if (!results.TryGetValue(directoryName, out jsonLines))
{
results.Add(directoryName, []);
if (!results.TryGetValue(directoryName, out jsonLines))
throw new Exception();
}
json = GetJson(input, markdownFile, blocks.AsReadOnly());
jsonLines.Add(json);
}
foreach (KeyValuePair<string, List<string>> keyValuePair in results)
{
json = string.Concat('[', Environment.NewLine, string.Join($",{Environment.NewLine}", keyValuePair.Value), Environment.NewLine, ']');
fileName = Path.Combine(input.Destination, $"{keyValuePair.Key}.json");
old = !File.Exists(fileName) ? string.Empty : File.ReadAllText(fileName);
if (json != old)
{
File.WriteAllText(fileName, json);
logger.LogInformation("Updated json file for <{fileName}>", fileName);
}
WriteBlocks(logger, input, markdownFile, fileName, blocks.AsReadOnly());
}
}
@ -1582,30 +1558,24 @@ internal static partial class HelperMarkdown
return results.AsReadOnly();
}
private static string GetJson(Input input, MarkdownFile markdownFile, ReadOnlyCollection<Block> blocks)
private static void WriteBlocks(ILogger<Worker> logger, Input input, MarkdownFile markdownFile, string fileName, ReadOnlyCollection<Block> blocks)
{
string result;
string paramCase;
List<string> lines = [];
string fileNameParamCase = GetParamCase(markdownFile.FileNameWithoutExtension);
foreach (Block block in blocks.OrderBy(l => l.Line))
{
paramCase = block.Title is null ? $"Line-{block.Line}" : GetParamCase(block.Title);
if (!string.IsNullOrEmpty(input.ReplaceWithTitle) && paramCase == input.ReplaceWithTitle)
paramCase = $"{fileNameParamCase}-{block.Line}";
paramCase = GetParamCase(markdownFile.FileNameWithoutExtension);
lines.Add($"\"{paramCase}\": {block.Json}");
}
result = string.Concat('{',
Environment.NewLine,
$"\"{fileNameParamCase}\": ",
'{',
Environment.NewLine,
string.Join($",{Environment.NewLine}", lines),
Environment.NewLine,
'}',
Environment.NewLine,
'}');
return result;
string old = !File.Exists(fileName) ? string.Empty : File.ReadAllText(fileName);
string json = string.Concat('{', Environment.NewLine, string.Join($",{Environment.NewLine}", lines), Environment.NewLine, '}');
if (json != old)
{
File.WriteAllText(fileName, json);
logger.LogInformation("Updated json file for <{fileName}>", fileName);
}
}
}