Relative path enhancement
Switch to Card Not Mapped
This commit is contained in:
parent
f810af3ebe
commit
b1e63df70b
@ -11,40 +11,6 @@ namespace File_Folder_Helper.Helpers;
|
|||||||
internal static partial class HelperMarkdown
|
internal static partial class HelperMarkdown
|
||||||
{
|
{
|
||||||
|
|
||||||
[GeneratedRegex("(~~)?(#)([a-zA-Z0-9]{6})(~~)?( )")]
|
|
||||||
private static partial Regex HtmlColor();
|
|
||||||
|
|
||||||
private record Input(string Source,
|
|
||||||
string? StartAt,
|
|
||||||
string? Destination);
|
|
||||||
|
|
||||||
private record Record(string Directory,
|
|
||||||
string File,
|
|
||||||
string[] Lines);
|
|
||||||
|
|
||||||
private record MarkdownFileAndLines(MarkdownFile MarkdownFile,
|
|
||||||
string[] Lines);
|
|
||||||
|
|
||||||
private record MarkdownExtra(ReadOnlyCollection<string>? Assignees,
|
|
||||||
ReadOnlyCollection<H2HexColor>? H2HexColorCollection,
|
|
||||||
ReadOnlyCollection<H2NoCheckboxes>? H2NoCheckboxesCollection,
|
|
||||||
ReadOnlyCollection<H2WithCheckboxes>? H2WithCheckboxesCollection,
|
|
||||||
string? RequestedDateTime);
|
|
||||||
|
|
||||||
private record MarkdownFileH1AndRelativePath(MarkdownFile? MarkdownFile, string[]? Lines, string? H1, string? RelativePath);
|
|
||||||
|
|
||||||
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
|
||||||
[JsonSerializable(typeof(Dictionary<string, JsonElement>))]
|
|
||||||
internal partial class DictionaryStringAndJsonElementSourceGenerationContext : JsonSerializerContext
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
|
||||||
[JsonSerializable(typeof(ReadOnlyDictionary<string, List<MarkdownFile>>))]
|
|
||||||
internal partial class ColumnAndLinksSourceGenerationContext : JsonSerializerContext
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void SetRecursiveLines(AppSettings appSettings, ILogger<Worker> logger, ReadOnlyDictionary<string, List<MarkdownFileAndLines>> keyValuePairs, string linkTitle, MarkdownFile markdownFile, string[] lines, List<char> indentations, List<string> recursiveLines)
|
private static void SetRecursiveLines(AppSettings appSettings, ILogger<Worker> logger, ReadOnlyDictionary<string, List<MarkdownFileAndLines>> keyValuePairs, string linkTitle, MarkdownFile markdownFile, string[] lines, List<char> indentations, List<string> recursiveLines)
|
||||||
{
|
{
|
||||||
if (recursiveLines is null)
|
if (recursiveLines is null)
|
||||||
@ -182,6 +148,9 @@ internal static partial class HelperMarkdown
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[GeneratedRegex("(~~)?(#)([a-zA-Z0-9]{6})(~~)?( )")]
|
||||||
|
private static partial Regex HtmlColor();
|
||||||
|
|
||||||
private static List<MarkdownFileAndLines> GetMarkdownFileAndLines(string file, List<MarkdownFileAndLines> markdownFiles)
|
private static List<MarkdownFileAndLines> GetMarkdownFileAndLines(string file, List<MarkdownFileAndLines> markdownFiles)
|
||||||
{
|
{
|
||||||
List<MarkdownFileAndLines> results = new();
|
List<MarkdownFileAndLines> results = new();
|
||||||
@ -240,7 +209,7 @@ internal static partial class HelperMarkdown
|
|||||||
line = lines[i];
|
line = lines[i];
|
||||||
if (line.Length < 3)
|
if (line.Length < 3)
|
||||||
continue;
|
continue;
|
||||||
if (line[..3] == "---")
|
if (h1LineNumber is null && line[..3] == "---")
|
||||||
{
|
{
|
||||||
frontMatterYamlEndLineNumber = i;
|
frontMatterYamlEndLineNumber = i;
|
||||||
continue;
|
continue;
|
||||||
@ -280,6 +249,90 @@ internal static partial class HelperMarkdown
|
|||||||
return (lines.ToList(), lineNumber);
|
return (lines.ToList(), lineNumber);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static MarkdownExtra GetMarkdownExtra(MarkdownFileAndLines markdownFileAndLines)
|
||||||
|
{
|
||||||
|
MarkdownExtra result;
|
||||||
|
int skip;
|
||||||
|
Match match;
|
||||||
|
string line;
|
||||||
|
int completed;
|
||||||
|
int notCompleted;
|
||||||
|
List<string> lines;
|
||||||
|
string? effort = null;
|
||||||
|
List<string> assignees = new();
|
||||||
|
string? requestedDateTime = null;
|
||||||
|
ReadOnlyCollection<Group> groups;
|
||||||
|
List<H2HexColor> h2HexColors = new();
|
||||||
|
List<H2NoCheckboxes> h2NoCheckboxes = new();
|
||||||
|
List<H2WithCheckboxes> h2WithCheckboxes = new();
|
||||||
|
if (markdownFileAndLines.MarkdownFile.LineNumber.FrontMatterYamlEnd is not null)
|
||||||
|
{
|
||||||
|
for (int i = 1; i < markdownFileAndLines.Lines.Length; i++)
|
||||||
|
{
|
||||||
|
line = markdownFileAndLines.Lines[i];
|
||||||
|
if (line.Length < 3)
|
||||||
|
continue;
|
||||||
|
if (line.Length > 8 && line[..8] == "effort: ")
|
||||||
|
{
|
||||||
|
effort = line[7..].Trim().Trim('"');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.Length > 10 && line[..10] == "assigned: ")
|
||||||
|
{
|
||||||
|
foreach (string item in line[10..].Split(',', StringSplitOptions.RemoveEmptyEntries))
|
||||||
|
assignees.Add(item.Trim().Trim('"'));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.Length > 11 && line[..11] == "requested: ")
|
||||||
|
{
|
||||||
|
requestedDateTime = line[10..].Trim().Trim('"');
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
if (line.Length > 3 && line[0] == '#' && line[1] == '#' && line[2] == ' ')
|
||||||
|
{
|
||||||
|
completed = 0;
|
||||||
|
notCompleted = 0;
|
||||||
|
match = HtmlColor().Match(line[3..]);
|
||||||
|
if (line.Length > 3 && match.Success)
|
||||||
|
{
|
||||||
|
groups = match.Groups.AsReadOnly();
|
||||||
|
skip = 3 + groups.Skip(1).Sum(l => l.Length);
|
||||||
|
h2HexColors.Add(new(line[skip..], $"#{groups.First(l => l.Value.Length == 6)}"));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
lines = new();
|
||||||
|
if (i + 1 == markdownFileAndLines.Lines.Length)
|
||||||
|
continue;
|
||||||
|
for (int j = i + 1; j < markdownFileAndLines.Lines.Length; j++)
|
||||||
|
{
|
||||||
|
line = markdownFileAndLines.Lines[j];
|
||||||
|
if (line.Length == 0)
|
||||||
|
continue;
|
||||||
|
if (line.Length > 2 && line[0] == '#')
|
||||||
|
break;
|
||||||
|
lines.Add(line);
|
||||||
|
if (line.Length < 5 || line[0] != '-' || line[1] != ' ' || line[2] != '[')
|
||||||
|
continue;
|
||||||
|
if (line[3] == ' ' && line[4] == ']')
|
||||||
|
notCompleted++;
|
||||||
|
else if (line[3] is 'x' or 'X' && line[4] == ']')
|
||||||
|
completed++;
|
||||||
|
}
|
||||||
|
if (completed != 0 || notCompleted != 0)
|
||||||
|
h2WithCheckboxes.Add(new(completed,
|
||||||
|
markdownFileAndLines.Lines[i][3..],
|
||||||
|
notCompleted,
|
||||||
|
notCompleted + completed));
|
||||||
|
else if (lines.Count > 0)
|
||||||
|
h2NoCheckboxes.Add(new(markdownFileAndLines.Lines[i][3..], new(lines)));
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
result = new(new(assignees), effort, new(h2HexColors), new(h2NoCheckboxes), new(h2WithCheckboxes), requestedDateTime);
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
private static List<MarkdownFileAndLines> Distinct(IEnumerable<MarkdownFileAndLines>? markdownFileAndLinesCollection)
|
private static List<MarkdownFileAndLines> Distinct(IEnumerable<MarkdownFileAndLines>? markdownFileAndLinesCollection)
|
||||||
{
|
{
|
||||||
List<MarkdownFileAndLines> results = new();
|
List<MarkdownFileAndLines> results = new();
|
||||||
@ -521,20 +574,15 @@ internal static partial class HelperMarkdown
|
|||||||
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(null,
|
markdownFile = new(fileInfo.CreationTime,
|
||||||
fileInfo.CreationTime,
|
|
||||||
fileInfo.DirectoryName,
|
fileInfo.DirectoryName,
|
||||||
fileInfo.Extension,
|
fileInfo.Extension,
|
||||||
file,
|
file,
|
||||||
fileInfo.Name,
|
fileInfo.Name,
|
||||||
fileNameWithoutExtension,
|
fileNameWithoutExtension,
|
||||||
h1,
|
h1,
|
||||||
null,
|
|
||||||
null,
|
|
||||||
null,
|
|
||||||
fileInfo.LastWriteTime,
|
fileInfo.LastWriteTime,
|
||||||
lineNumber,
|
lineNumber,
|
||||||
null,
|
|
||||||
type);
|
type);
|
||||||
if (force || input.StartAt is null || file.StartsWith(input.StartAt))
|
if (force || input.StartAt is null || file.StartsWith(input.StartAt))
|
||||||
results.Add(key, new(markdownFile, lines.ToArray()));
|
results.Add(key, new(markdownFile, lines.ToArray()));
|
||||||
@ -544,6 +592,115 @@ internal static partial class HelperMarkdown
|
|||||||
return new(results);
|
return new(results);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static ReadOnlyDictionary<string, List<Card>> GetColumnsToCards(Input input, ReadOnlyDictionary<string, MarkdownFileAndLines> relativeToCollection)
|
||||||
|
{
|
||||||
|
Dictionary<string, List<Card>> results = new();
|
||||||
|
Card card;
|
||||||
|
string key;
|
||||||
|
string[] lines;
|
||||||
|
string[] segmentsA;
|
||||||
|
string? column = null;
|
||||||
|
List<Card> cards = new();
|
||||||
|
MarkdownFile markdownFile;
|
||||||
|
MarkdownExtra markdownExtra;
|
||||||
|
List<string> allKeys = new();
|
||||||
|
MarkdownFileAndLines? markdownFileAndLines;
|
||||||
|
foreach (KeyValuePair<string, MarkdownFileAndLines> relativeTo in relativeToCollection)
|
||||||
|
allKeys.Add(relativeTo.Key);
|
||||||
|
foreach (KeyValuePair<string, MarkdownFileAndLines> relativeTo in relativeToCollection)
|
||||||
|
{
|
||||||
|
if (relativeTo.Value.Lines.Length == 0)
|
||||||
|
continue;
|
||||||
|
lines = relativeTo.Value.Lines;
|
||||||
|
markdownFile = relativeTo.Value.MarkdownFile;
|
||||||
|
if (markdownFile.FileNameWithoutExtension != "index" || markdownFile.Type != "Kanban")
|
||||||
|
continue;
|
||||||
|
if (!File.Exists(markdownFile.File))
|
||||||
|
continue;
|
||||||
|
for (int i = 0; i < lines.Length; i++)
|
||||||
|
{
|
||||||
|
if (lines[i].Length < 4 || lines[i][0] != '#' || lines[i][1] != '#' || lines[i][2] != ' ')
|
||||||
|
continue;
|
||||||
|
if (cards.Count > 1)
|
||||||
|
{
|
||||||
|
if (column is null)
|
||||||
|
throw new NullReferenceException(nameof(column));
|
||||||
|
results.Add(column, cards);
|
||||||
|
cards = new();
|
||||||
|
}
|
||||||
|
column = lines[i][3..].TrimEnd();
|
||||||
|
if (lines.Length == i + 1)
|
||||||
|
continue;
|
||||||
|
for (int j = i + 1; j < lines.Length; j++)
|
||||||
|
{
|
||||||
|
if (lines[j].Length < 5)
|
||||||
|
continue;
|
||||||
|
if (lines[j].Length >= 4 && lines[j][0] == '#' && lines[j][1] == '#' && lines[j][2] == ' ')
|
||||||
|
break;
|
||||||
|
segmentsA = lines[j].Split("](");
|
||||||
|
if (segmentsA.Length != 2 || segmentsA[1][^1] != ')')
|
||||||
|
continue;
|
||||||
|
key = Path.GetRelativePath(input.Source, Path.Combine(markdownFile.Directory, segmentsA[1][..^1]));
|
||||||
|
if (!allKeys.Remove(key))
|
||||||
|
throw new NotSupportedException();
|
||||||
|
if (!relativeToCollection.TryGetValue(key, out markdownFileAndLines))
|
||||||
|
continue;
|
||||||
|
markdownExtra = GetMarkdownExtra(markdownFileAndLines);
|
||||||
|
card = new(markdownExtra.Assignees,
|
||||||
|
markdownFileAndLines.MarkdownFile.CreationDateTime,
|
||||||
|
markdownFileAndLines.MarkdownFile.Directory,
|
||||||
|
markdownExtra.Effort,
|
||||||
|
markdownFileAndLines.MarkdownFile.Extension,
|
||||||
|
markdownFileAndLines.MarkdownFile.File,
|
||||||
|
markdownFileAndLines.MarkdownFile.FileName,
|
||||||
|
markdownFileAndLines.MarkdownFile.FileNameWithoutExtension,
|
||||||
|
markdownFileAndLines.MarkdownFile.H1,
|
||||||
|
markdownExtra.H2HexColorCollection,
|
||||||
|
markdownExtra.H2NoCheckboxesCollection,
|
||||||
|
markdownExtra.H2WithCheckboxesCollection,
|
||||||
|
markdownFileAndLines.MarkdownFile.LastWriteDateTime,
|
||||||
|
markdownFileAndLines.MarkdownFile.LineNumber,
|
||||||
|
markdownExtra.RequestedDateTime,
|
||||||
|
markdownFileAndLines.MarkdownFile.Type);
|
||||||
|
cards.Add(card);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
foreach (string notLinkedKey in allKeys)
|
||||||
|
{
|
||||||
|
key = notLinkedKey;
|
||||||
|
if (!relativeToCollection.TryGetValue(key, out markdownFileAndLines))
|
||||||
|
continue;
|
||||||
|
if (markdownFileAndLines.MarkdownFile.LineNumber.FrontMatterYamlEnd is null)
|
||||||
|
continue;
|
||||||
|
markdownExtra = GetMarkdownExtra(markdownFileAndLines);
|
||||||
|
card = new(markdownExtra.Assignees,
|
||||||
|
markdownFileAndLines.MarkdownFile.CreationDateTime,
|
||||||
|
markdownFileAndLines.MarkdownFile.Directory,
|
||||||
|
markdownExtra.Effort,
|
||||||
|
markdownFileAndLines.MarkdownFile.Extension,
|
||||||
|
markdownFileAndLines.MarkdownFile.File,
|
||||||
|
markdownFileAndLines.MarkdownFile.FileName,
|
||||||
|
markdownFileAndLines.MarkdownFile.FileNameWithoutExtension,
|
||||||
|
markdownFileAndLines.MarkdownFile.H1,
|
||||||
|
markdownExtra.H2HexColorCollection,
|
||||||
|
markdownExtra.H2NoCheckboxesCollection,
|
||||||
|
markdownExtra.H2WithCheckboxesCollection,
|
||||||
|
markdownFileAndLines.MarkdownFile.LastWriteDateTime,
|
||||||
|
markdownFileAndLines.MarkdownFile.LineNumber,
|
||||||
|
markdownExtra.RequestedDateTime,
|
||||||
|
markdownFileAndLines.MarkdownFile.Type);
|
||||||
|
cards.Add(card);
|
||||||
|
}
|
||||||
|
if (cards.Count > 1)
|
||||||
|
{
|
||||||
|
column = "Not Linked";
|
||||||
|
results.Add(column, cards);
|
||||||
|
cards = new();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return new(results);
|
||||||
|
}
|
||||||
|
|
||||||
private static MarkdownFileAndLines? GetMarkdownFile(ReadOnlyDictionary<string, List<MarkdownFileAndLines>> keyValuePairs, MarkdownFile markdownFile, string file)
|
private static MarkdownFileAndLines? GetMarkdownFile(ReadOnlyDictionary<string, List<MarkdownFileAndLines>> keyValuePairs, MarkdownFile markdownFile, string file)
|
||||||
{
|
{
|
||||||
MarkdownFileAndLines? result;
|
MarkdownFileAndLines? result;
|
||||||
@ -976,6 +1133,18 @@ internal static partial class HelperMarkdown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SaveColumnToCards(Input input, ReadOnlyDictionary<string, MarkdownFileAndLines> relativeToCollection)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrEmpty(input.StartAt) || string.IsNullOrEmpty(input.Destination))
|
||||||
|
throw new NotSupportedException();
|
||||||
|
ReadOnlyDictionary<string, List<Card>> columnsToCards = GetColumnsToCards(input, relativeToCollection);
|
||||||
|
if (columnsToCards.Count > 0)
|
||||||
|
{
|
||||||
|
string json = JsonSerializer.Serialize(columnsToCards, ColumnsAndCardsSourceGenerationContext.Default.ReadOnlyDictionaryStringListCard);
|
||||||
|
File.WriteAllText(Path.Combine(input.Destination, $"{nameof(columnsToCards)}.json"), json);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static List<Record> GetWithLinksForHugo(AppSettings appSettings, Input input)
|
private static List<Record> GetWithLinksForHugo(AppSettings appSettings, Input input)
|
||||||
{
|
{
|
||||||
List<Record> results = new();
|
List<Record> results = new();
|
||||||
@ -1056,6 +1225,43 @@ internal static partial class HelperMarkdown
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private record Input(string Source,
|
||||||
|
string? StartAt,
|
||||||
|
string? Destination);
|
||||||
|
|
||||||
|
private record Record(string Directory,
|
||||||
|
string File,
|
||||||
|
string[] Lines);
|
||||||
|
|
||||||
|
private record MarkdownFile(DateTime CreationDateTime,
|
||||||
|
string Directory,
|
||||||
|
string Extension,
|
||||||
|
string File,
|
||||||
|
string FileName,
|
||||||
|
string FileNameWithoutExtension,
|
||||||
|
string H1,
|
||||||
|
DateTime LastWriteDateTime,
|
||||||
|
LineNumber LineNumber,
|
||||||
|
string Type);
|
||||||
|
|
||||||
|
private record MarkdownFileAndLines(MarkdownFile MarkdownFile,
|
||||||
|
string[] Lines);
|
||||||
|
|
||||||
|
private record MarkdownExtra(ReadOnlyCollection<string>? Assignees,
|
||||||
|
string? Effort,
|
||||||
|
ReadOnlyCollection<H2HexColor>? H2HexColorCollection,
|
||||||
|
ReadOnlyCollection<H2NoCheckboxes>? H2NoCheckboxesCollection,
|
||||||
|
ReadOnlyCollection<H2WithCheckboxes>? H2WithCheckboxesCollection,
|
||||||
|
string? RequestedDateTime);
|
||||||
|
|
||||||
|
private record MarkdownFileH1AndRelativePath(MarkdownFile? MarkdownFile, string[]? Lines, string? H1, string? RelativePath);
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonSerializable(typeof(Dictionary<string, JsonElement>))]
|
||||||
|
internal partial class DictionaryStringAndJsonElementSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
private static (string type, string h1) GetTypeAndH1(AppSettings appSettings, string h1, List<string> lines, LineNumber lineNumber)
|
private static (string type, string h1) GetTypeAndH1(AppSettings appSettings, string h1, List<string> lines, LineNumber lineNumber)
|
||||||
{
|
{
|
||||||
string type = lineNumber.Type is null ? appSettings.DefaultNoteType : lines[lineNumber.Type.Value][5..].Trim().Trim('"');
|
string type = lineNumber.Type is null ? appSettings.DefaultNoteType : lines[lineNumber.Type.Value][5..].Trim().Trim('"');
|
||||||
@ -1192,179 +1398,7 @@ internal static partial class HelperMarkdown
|
|||||||
Write(input, markdownFileAndLinesCollection);
|
Write(input, markdownFileAndLinesCollection);
|
||||||
}
|
}
|
||||||
if (!string.IsNullOrEmpty(input.StartAt) && !string.IsNullOrEmpty(input.Destination))
|
if (!string.IsNullOrEmpty(input.StartAt) && !string.IsNullOrEmpty(input.Destination))
|
||||||
Save(input, relativeToCollection);
|
SaveColumnToCards(input, relativeToCollection);
|
||||||
string directory = Path.Combine(Environment.CurrentDirectory, ".vscode");
|
|
||||||
if (!Directory.Exists(directory))
|
|
||||||
{
|
|
||||||
string json;
|
|
||||||
MarkdownFile markdownFile = relativeToCollection.ElementAt(0).Value.MarkdownFile;
|
|
||||||
json = JsonSerializer.Serialize(markdownFile, MarkdownFileSourceGenerationContext.Default.MarkdownFile);
|
|
||||||
if (json != "{}")
|
|
||||||
{
|
|
||||||
json = JsonSerializer.Serialize(relativeToCollection.Select(l => l.Value.MarkdownFile).ToArray(), MarkdownFileCollectionSourceGenerationContext.Default.MarkdownFileArray);
|
|
||||||
File.WriteAllText($"{DateTime.Now.Ticks}.json", json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static void Save(Input input, ReadOnlyDictionary<string, MarkdownFileAndLines> relativeToCollection)
|
|
||||||
{
|
|
||||||
if (string.IsNullOrEmpty(input.StartAt) || string.IsNullOrEmpty(input.Destination))
|
|
||||||
throw new NotSupportedException();
|
|
||||||
ReadOnlyDictionary<string, List<MarkdownFile>> columnsToLinks = GetColumnsToLinks(input, relativeToCollection);
|
|
||||||
if (columnsToLinks.Count > 0)
|
|
||||||
{
|
|
||||||
string json = JsonSerializer.Serialize(columnsToLinks, ColumnAndLinksSourceGenerationContext.Default.ReadOnlyDictionaryStringListMarkdownFile);
|
|
||||||
File.WriteAllText(Path.Combine(input.Destination, $"{nameof(columnsToLinks)}.json"), json);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private static ReadOnlyDictionary<string, List<MarkdownFile>> GetColumnsToLinks(Input input, ReadOnlyDictionary<string, MarkdownFileAndLines> relativeToCollection)
|
|
||||||
{
|
|
||||||
Dictionary<string, List<MarkdownFile>> results = new();
|
|
||||||
string key;
|
|
||||||
string[] lines;
|
|
||||||
string[] segmentsA;
|
|
||||||
string? column = null;
|
|
||||||
MarkdownFile markdownFile;
|
|
||||||
MarkdownExtra markdownExtra;
|
|
||||||
List<MarkdownFile> links = new();
|
|
||||||
MarkdownFileAndLines? markdownFileAndLines;
|
|
||||||
foreach (KeyValuePair<string, MarkdownFileAndLines> relativeTo in relativeToCollection)
|
|
||||||
{
|
|
||||||
if (relativeTo.Value.Lines.Length == 0)
|
|
||||||
continue;
|
|
||||||
lines = relativeTo.Value.Lines;
|
|
||||||
markdownFile = relativeTo.Value.MarkdownFile;
|
|
||||||
if (markdownFile.FileNameWithoutExtension != "index" && markdownFile.Directory.EndsWith(".kanbn"))
|
|
||||||
continue;
|
|
||||||
if (!File.Exists(markdownFile.File))
|
|
||||||
continue;
|
|
||||||
for (int i = 0; i < lines.Length; i++)
|
|
||||||
{
|
|
||||||
if (lines[i].Length < 4 || lines[i][0] != '#' || lines[i][1] != '#' || lines[i][2] != ' ')
|
|
||||||
continue;
|
|
||||||
if (links.Count > 1)
|
|
||||||
{
|
|
||||||
if (column is null)
|
|
||||||
throw new NullReferenceException(nameof(column));
|
|
||||||
results.Add(column, links);
|
|
||||||
links = new();
|
|
||||||
}
|
|
||||||
column = lines[i][3..].TrimEnd();
|
|
||||||
if (lines.Length == i + 1)
|
|
||||||
continue;
|
|
||||||
for (int j = i + 1; j < lines.Length; j++)
|
|
||||||
{
|
|
||||||
if (lines[j].Length < 5)
|
|
||||||
continue;
|
|
||||||
if (lines[j].Length >= 4 && lines[j][0] == '#' && lines[j][1] == '#' && lines[j][2] == ' ')
|
|
||||||
break;
|
|
||||||
segmentsA = lines[j].Split("](");
|
|
||||||
if (segmentsA.Length != 2 || segmentsA[1][^1] != ')')
|
|
||||||
continue;
|
|
||||||
key = Path.GetRelativePath(input.Source, Path.Combine(input.Source, segmentsA[1][..^1]));
|
|
||||||
if (!relativeToCollection.TryGetValue(key, out markdownFileAndLines))
|
|
||||||
continue;
|
|
||||||
markdownExtra = GetMarkdownExtra(markdownFileAndLines);
|
|
||||||
markdownFile = new(markdownExtra.Assignees,
|
|
||||||
markdownFileAndLines.MarkdownFile.CreationDateTime,
|
|
||||||
markdownFileAndLines.MarkdownFile.Directory,
|
|
||||||
markdownFileAndLines.MarkdownFile.Extension,
|
|
||||||
markdownFileAndLines.MarkdownFile.File,
|
|
||||||
markdownFileAndLines.MarkdownFile.FileName,
|
|
||||||
markdownFileAndLines.MarkdownFile.FileNameWithoutExtension,
|
|
||||||
markdownFileAndLines.MarkdownFile.H1,
|
|
||||||
markdownExtra.H2HexColorCollection,
|
|
||||||
markdownExtra.H2NoCheckboxesCollection,
|
|
||||||
markdownExtra.H2WithCheckboxesCollection,
|
|
||||||
markdownFileAndLines.MarkdownFile.LastWriteDateTime,
|
|
||||||
markdownFileAndLines.MarkdownFile.LineNumber,
|
|
||||||
markdownExtra.RequestedDateTime,
|
|
||||||
markdownFileAndLines.MarkdownFile.Type);
|
|
||||||
links.Add(markdownFile);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return new(results);
|
|
||||||
}
|
|
||||||
|
|
||||||
private static MarkdownExtra GetMarkdownExtra(MarkdownFileAndLines markdownFileAndLines)
|
|
||||||
{
|
|
||||||
MarkdownExtra result;
|
|
||||||
int skip;
|
|
||||||
Match match;
|
|
||||||
string line;
|
|
||||||
int completed;
|
|
||||||
int notCompleted;
|
|
||||||
List<string> lines;
|
|
||||||
List<string> assignees = new();
|
|
||||||
string? requestedDateTime = null;
|
|
||||||
ReadOnlyCollection<Group> groups;
|
|
||||||
List<H2HexColor> h2HexColors = new();
|
|
||||||
List<H2NoCheckboxes> h2NoCheckboxes = new();
|
|
||||||
List<H2WithCheckboxes> h2WithCheckboxes = new();
|
|
||||||
if (markdownFileAndLines.MarkdownFile.LineNumber.FrontMatterYamlEnd is not null)
|
|
||||||
{
|
|
||||||
for (int i = 1; i < markdownFileAndLines.Lines.Length; i++)
|
|
||||||
{
|
|
||||||
line = markdownFileAndLines.Lines[i];
|
|
||||||
if (line.Length < 3)
|
|
||||||
continue;
|
|
||||||
if (line.Length > 10 && line[..10] == "assigned: ")
|
|
||||||
{
|
|
||||||
foreach (string item in line[10..].Split(','))
|
|
||||||
assignees.Add(item.Trim().Trim('"'));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (line.Length > 11 && line[..11] == "requested: ")
|
|
||||||
{
|
|
||||||
requestedDateTime = line[10..].Trim().Trim('"');
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
if (line.Length > 3 && line[0] == '#' && line[1] == '#' && line[2] == ' ')
|
|
||||||
{
|
|
||||||
completed = 0;
|
|
||||||
notCompleted = 0;
|
|
||||||
match = HtmlColor().Match(line[3..]);
|
|
||||||
if (line.Length > 3 && match.Success)
|
|
||||||
{
|
|
||||||
groups = match.Groups.AsReadOnly();
|
|
||||||
skip = 3 + groups.Skip(1).Sum(l => l.Length);
|
|
||||||
h2HexColors.Add(new(line[skip..], $"#{groups.First(l => l.Value.Length == 6)}"));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
lines = new();
|
|
||||||
if (i + 1 == markdownFileAndLines.Lines.Length)
|
|
||||||
continue;
|
|
||||||
for (int j = i + 1; j < markdownFileAndLines.Lines.Length; j++)
|
|
||||||
{
|
|
||||||
line = markdownFileAndLines.Lines[j];
|
|
||||||
if (line.Length == 0)
|
|
||||||
continue;
|
|
||||||
if (line.Length > 2 && line[0] == '#')
|
|
||||||
break;
|
|
||||||
lines.Add(line);
|
|
||||||
if (line.Length < 5 || line[0] != '-' || line[1] != ' ' || line[2] != '[')
|
|
||||||
continue;
|
|
||||||
if (line[3] == ' ' && line[4] == ']')
|
|
||||||
notCompleted++;
|
|
||||||
else if (line[3] is 'x' or 'X' && line[4] == ']')
|
|
||||||
completed++;
|
|
||||||
}
|
|
||||||
if (completed != 0 || notCompleted != 0)
|
|
||||||
h2WithCheckboxes.Add(new(completed,
|
|
||||||
markdownFileAndLines.Lines[i][3..],
|
|
||||||
notCompleted,
|
|
||||||
notCompleted + completed));
|
|
||||||
else if (lines.Count > 0)
|
|
||||||
h2NoCheckboxes.Add(new(markdownFileAndLines.Lines[i][3..], new(lines)));
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
result = new(new(assignees), new(h2HexColors), new(h2NoCheckboxes), new(h2WithCheckboxes), requestedDateTime);
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void MarkdownConvertLinksForHugo(AppSettings appSettings, ILogger<Worker> logger, List<string> args)
|
internal static void MarkdownConvertLinksForHugo(AppSettings appSettings, ILogger<Worker> logger, List<string> args)
|
||||||
|
@ -10,31 +10,22 @@ internal static class HelperPdfStripperWrapper
|
|||||||
string? Key,
|
string? Key,
|
||||||
char? Parser);
|
char? Parser);
|
||||||
|
|
||||||
private static Input GetInput(List<string> args)
|
private static string GetTextFromPDF(string pdfTextStripperFileName, string sourceFileNamePdf, string destinationFileName)
|
||||||
{
|
{
|
||||||
string? d = null;
|
string result;
|
||||||
string? k = null;
|
ProcessStartInfo processStartInfo = new(pdfTextStripperFileName, $"s \"{sourceFileNamePdf}\"")
|
||||||
string? p = null;
|
|
||||||
for (int i = 1; i < args.Count; i++)
|
|
||||||
{
|
{
|
||||||
if (args[i].Length == 2 && i + 1 < args.Count)
|
UseShellExecute = false,
|
||||||
{
|
RedirectStandardError = true,
|
||||||
if (args[i][1] == 'd')
|
RedirectStandardOutput = true,
|
||||||
d = Path.GetFullPath(args[i + 1]);
|
};
|
||||||
else if (args[i][1] == 'k')
|
Process? process = Process.Start(processStartInfo);
|
||||||
k = args[i + 1].Trim();
|
_ = process?.WaitForExit(30000);
|
||||||
else if (args[i][1] == 'p')
|
if (!File.Exists(destinationFileName))
|
||||||
p = args[i + 1];
|
result = string.Empty;
|
||||||
i++;
|
else
|
||||||
}
|
result = File.ReadAllText(destinationFileName);
|
||||||
}
|
return result;
|
||||||
string directoryName = Path.GetFileName(args[0]);
|
|
||||||
if (!string.IsNullOrEmpty(d) && !d.EndsWith(directoryName))
|
|
||||||
d = Path.Combine(d, directoryName);
|
|
||||||
if (!string.IsNullOrEmpty(d) && !Directory.Exists(d))
|
|
||||||
_ = Directory.CreateDirectory(d);
|
|
||||||
char? parser = p is null ? null : p == "S" ? 'S' : p == "G" ? 'G' : p == "K" ? 'K' : null;
|
|
||||||
return new(d, k, parser);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetGhostTextFromPDF(string ghostPCLFileName, string sourceFileNamePdf, string destinationFileName)
|
private static string GetGhostTextFromPDF(string ghostPCLFileName, string sourceFileNamePdf, string destinationFileName)
|
||||||
@ -69,22 +60,31 @@ internal static class HelperPdfStripperWrapper
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static string GetTextFromPDF(string pdfTextStripperFileName, string sourceFileNamePdf, string destinationFileName)
|
private static Input GetInput(List<string> args)
|
||||||
{
|
{
|
||||||
string result;
|
string? d = null;
|
||||||
ProcessStartInfo processStartInfo = new(pdfTextStripperFileName, $"s \"{sourceFileNamePdf}\"")
|
string? k = null;
|
||||||
|
string? p = null;
|
||||||
|
for (int i = 1; i < args.Count; i++)
|
||||||
{
|
{
|
||||||
UseShellExecute = false,
|
if (args[i].Length == 2 && i + 1 < args.Count)
|
||||||
RedirectStandardError = true,
|
{
|
||||||
RedirectStandardOutput = true,
|
if (args[i][1] == 'd')
|
||||||
};
|
d = Path.GetFullPath(args[i + 1]);
|
||||||
Process? process = Process.Start(processStartInfo);
|
else if (args[i][1] == 'k')
|
||||||
_ = process?.WaitForExit(30000);
|
k = args[i + 1].Trim();
|
||||||
if (!File.Exists(destinationFileName))
|
else if (args[i][1] == 'p')
|
||||||
result = string.Empty;
|
p = args[i + 1];
|
||||||
else
|
i++;
|
||||||
result = File.ReadAllText(destinationFileName);
|
}
|
||||||
return result;
|
}
|
||||||
|
string directoryName = Path.GetFileName(args[0]);
|
||||||
|
if (!string.IsNullOrEmpty(d) && !d.EndsWith(directoryName))
|
||||||
|
d = Path.Combine(d, directoryName);
|
||||||
|
if (!string.IsNullOrEmpty(d) && !Directory.Exists(d))
|
||||||
|
_ = Directory.CreateDirectory(d);
|
||||||
|
char? parser = p is null ? null : p == "S" ? 'S' : p == "G" ? 'G' : p == "K" ? 'K' : null;
|
||||||
|
return new(d, k, parser);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ParseSave(ILogger log, string pdfTextStripperFileName, string ghostPCLFileName, string kofaxFileName, string destinationDirectory, char parser, string[] files)
|
private static void ParseSave(ILogger log, string pdfTextStripperFileName, string ghostPCLFileName, string kofaxFileName, string destinationDirectory, char parser, string[] files)
|
||||||
@ -108,6 +108,31 @@ internal static class HelperPdfStripperWrapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void ParseStrip(ILogger log, string destinationDirectory, string key, string[] files)
|
||||||
|
{
|
||||||
|
string[] lines;
|
||||||
|
string fileName;
|
||||||
|
string[] segments;
|
||||||
|
List<string> collection = new();
|
||||||
|
foreach (string file in files)
|
||||||
|
{
|
||||||
|
lines = File.ReadAllLines(file);
|
||||||
|
fileName = Path.GetFileName(file);
|
||||||
|
foreach (string line in lines)
|
||||||
|
{
|
||||||
|
segments = line.Split(':');
|
||||||
|
if (segments.Length < 2)
|
||||||
|
continue;
|
||||||
|
if (segments[0].Trim() != key)
|
||||||
|
continue;
|
||||||
|
collection.Add($"{fileName}\t{line}");
|
||||||
|
}
|
||||||
|
log.LogInformation("<{fileName}>", fileName);
|
||||||
|
}
|
||||||
|
if (collection.Count > 0)
|
||||||
|
File.WriteAllLines(Path.Combine(destinationDirectory, $"{key}.txt"), collection);
|
||||||
|
}
|
||||||
|
|
||||||
internal static void ParseSave(ILogger log, List<string> args)
|
internal static void ParseSave(ILogger log, List<string> args)
|
||||||
{
|
{
|
||||||
string pdfTextStripperFileName = Path.Combine(AppContext.BaseDirectory, "PDF-Text-Stripper.exe");
|
string pdfTextStripperFileName = Path.Combine(AppContext.BaseDirectory, "PDF-Text-Stripper.exe");
|
||||||
@ -146,31 +171,6 @@ internal static class HelperPdfStripperWrapper
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void ParseStrip(ILogger log, string destinationDirectory, string key, string[] files)
|
|
||||||
{
|
|
||||||
string[] lines;
|
|
||||||
string fileName;
|
|
||||||
string[] segments;
|
|
||||||
List<string> collection = new();
|
|
||||||
foreach (string file in files)
|
|
||||||
{
|
|
||||||
lines = File.ReadAllLines(file);
|
|
||||||
fileName = Path.GetFileName(file);
|
|
||||||
foreach (string line in lines)
|
|
||||||
{
|
|
||||||
segments = line.Split(':');
|
|
||||||
if (segments.Length < 2)
|
|
||||||
continue;
|
|
||||||
if (segments[0].Trim() != key)
|
|
||||||
continue;
|
|
||||||
collection.Add($"{fileName}\t{line}");
|
|
||||||
}
|
|
||||||
log.LogInformation("<{fileName}>", fileName);
|
|
||||||
}
|
|
||||||
if (collection.Count > 0)
|
|
||||||
File.WriteAllLines(Path.Combine(destinationDirectory, $"{key}.txt"), collection);
|
|
||||||
}
|
|
||||||
|
|
||||||
internal static void ParseStrip(ILogger log, List<string> args)
|
internal static void ParseStrip(ILogger log, List<string> args)
|
||||||
{
|
{
|
||||||
if (DateTime.Now > new DateTime(2023, 9, 15))
|
if (DateTime.Now > new DateTime(2023, 9, 15))
|
||||||
|
@ -3,6 +3,32 @@ namespace File_Folder_Helper.Helpers;
|
|||||||
internal static class HelperTooLong
|
internal static class HelperTooLong
|
||||||
{
|
{
|
||||||
|
|
||||||
|
internal static void TooLong(string workingDirectory, bool delete)
|
||||||
|
{
|
||||||
|
string[] files;
|
||||||
|
string destination;
|
||||||
|
string? parentDirectory;
|
||||||
|
string[] directories = Directory.GetDirectories(workingDirectory, "*", SearchOption.TopDirectoryOnly);
|
||||||
|
for (int i = 0; i < directories.Length; i++)
|
||||||
|
{
|
||||||
|
if (delete)
|
||||||
|
{
|
||||||
|
Directory.Delete(directories[i], recursive: true);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
files = Directory.GetFiles(directories[i], "*", SearchOption.TopDirectoryOnly);
|
||||||
|
for (int f = 0; f < files.Length; f++)
|
||||||
|
File.Delete(files[f]);
|
||||||
|
parentDirectory = Path.GetDirectoryName(directories[i]);
|
||||||
|
if (string.IsNullOrEmpty(parentDirectory))
|
||||||
|
continue;
|
||||||
|
destination = Path.Combine(parentDirectory, i.ToString());
|
||||||
|
if (Path.GetFileName(directories[i]).Length > 3)
|
||||||
|
Directory.Move(directories[i], destination);
|
||||||
|
TooLong(destination, delete);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void MoveFiles(string yearName, string personKeyFormattedDirectory, string personNameDirectory, string personNameDirectoryName)
|
private static void MoveFiles(string yearName, string personKeyFormattedDirectory, string personNameDirectory, string personNameDirectoryName)
|
||||||
{
|
{
|
||||||
string? checkFile;
|
string? checkFile;
|
||||||
@ -85,30 +111,4 @@ internal static class HelperTooLong
|
|||||||
_ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(directory);
|
_ = HelperDeleteEmptyDirectories.DeleteEmptyDirectories(directory);
|
||||||
}
|
}
|
||||||
|
|
||||||
internal static void TooLong(string workingDirectory, bool delete)
|
|
||||||
{
|
|
||||||
string[] files;
|
|
||||||
string destination;
|
|
||||||
string? parentDirectory;
|
|
||||||
string[] directories = Directory.GetDirectories(workingDirectory, "*", SearchOption.TopDirectoryOnly);
|
|
||||||
for (int i = 0; i < directories.Length; i++)
|
|
||||||
{
|
|
||||||
if (delete)
|
|
||||||
{
|
|
||||||
Directory.Delete(directories[i], recursive: true);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
files = Directory.GetFiles(directories[i], "*", SearchOption.TopDirectoryOnly);
|
|
||||||
for (int f = 0; f < files.Length; f++)
|
|
||||||
File.Delete(files[f]);
|
|
||||||
parentDirectory = Path.GetDirectoryName(directories[i]);
|
|
||||||
if (string.IsNullOrEmpty(parentDirectory))
|
|
||||||
continue;
|
|
||||||
destination = Path.Combine(parentDirectory, i.ToString());
|
|
||||||
if (Path.GetFileName(directories[i]).Length > 3)
|
|
||||||
Directory.Move(directories[i], destination);
|
|
||||||
TooLong(destination, delete);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
33
Models/Card.cs
Normal file
33
Models/Card.cs
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
using System.Collections.ObjectModel;
|
||||||
|
using System.Text.Json.Serialization;
|
||||||
|
|
||||||
|
namespace File_Folder_Helper.Models;
|
||||||
|
|
||||||
|
internal record Card(ReadOnlyCollection<string>? Assignees,
|
||||||
|
DateTime CreationDateTime,
|
||||||
|
string Directory,
|
||||||
|
string? Effort,
|
||||||
|
string Extension,
|
||||||
|
string File,
|
||||||
|
string FileName,
|
||||||
|
string FileNameWithoutExtension,
|
||||||
|
string H1,
|
||||||
|
ReadOnlyCollection<H2HexColor>? H2HexColorCollection,
|
||||||
|
ReadOnlyCollection<H2NoCheckboxes>? H2NoCheckboxesCollection,
|
||||||
|
ReadOnlyCollection<H2WithCheckboxes>? H2WithCheckboxesCollection,
|
||||||
|
DateTime LastWriteDateTime,
|
||||||
|
LineNumber LineNumber,
|
||||||
|
string? RequestedDateTime,
|
||||||
|
string Type);
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true)]
|
||||||
|
[JsonSerializable(typeof(Card))]
|
||||||
|
internal partial class CardSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
[JsonSourceGenerationOptions(WriteIndented = true, DefaultIgnoreCondition = JsonIgnoreCondition.WhenWritingNull)]
|
||||||
|
[JsonSerializable(typeof(ReadOnlyDictionary<string, List<Card>>))]
|
||||||
|
internal partial class ColumnsAndCardsSourceGenerationContext : JsonSerializerContext
|
||||||
|
{
|
||||||
|
}
|
@ -1,32 +0,0 @@
|
|||||||
using System.Collections.ObjectModel;
|
|
||||||
using System.Text.Json.Serialization;
|
|
||||||
|
|
||||||
namespace File_Folder_Helper.Models;
|
|
||||||
|
|
||||||
internal record MarkdownFile(ReadOnlyCollection<string>? Assignees,
|
|
||||||
DateTime CreationDateTime,
|
|
||||||
string Directory,
|
|
||||||
string Extension,
|
|
||||||
string File,
|
|
||||||
string FileName,
|
|
||||||
string FileNameWithoutExtension,
|
|
||||||
string H1,
|
|
||||||
ReadOnlyCollection<H2HexColor>? H2HexColorCollection,
|
|
||||||
ReadOnlyCollection<H2NoCheckboxes>? H2NoCheckboxesCollection,
|
|
||||||
ReadOnlyCollection<H2WithCheckboxes>? H2WithCheckboxesCollection,
|
|
||||||
DateTime LastWriteDateTime,
|
|
||||||
LineNumber LineNumber,
|
|
||||||
string? RequestedDateTime,
|
|
||||||
string Type);
|
|
||||||
|
|
||||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
|
||||||
[JsonSerializable(typeof(MarkdownFile))]
|
|
||||||
internal partial class MarkdownFileSourceGenerationContext : JsonSerializerContext
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
[JsonSourceGenerationOptions(WriteIndented = true)]
|
|
||||||
[JsonSerializable(typeof(MarkdownFile[]))]
|
|
||||||
internal partial class MarkdownFileCollectionSourceGenerationContext : JsonSerializerContext
|
|
||||||
{
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user