Compare commits
1 Commits
Author | SHA1 | Date | |
---|---|---|---|
1522c54c44 |
4
.vscode/launch.json
vendored
4
.vscode/launch.json
vendored
@ -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",
|
||||
|
@ -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,13 @@ 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);
|
||||
WriteBlocks(logger, input, markdownFile, fileName, blocks.AsReadOnly());
|
||||
}
|
||||
foreach (KeyValuePair<string, List<string>> keyValuePair in results)
|
||||
string[] files = Directory.GetFiles(input.Destination, "*.json", SearchOption.TopDirectoryOnly);
|
||||
foreach (string file in files)
|
||||
{
|
||||
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);
|
||||
}
|
||||
if (!fileNames.Contains(file))
|
||||
File.Delete(file);
|
||||
}
|
||||
}
|
||||
|
||||
@ -1582,30 +1564,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);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user