diff --git a/.kanbn/board.md b/.kanbn/board.md new file mode 100644 index 0000000..6b41138 Binary files /dev/null and b/.kanbn/board.md differ diff --git a/Helpers/HelperCreateNoteFiles.cs b/Helpers/HelperCreateNoteFiles.cs index 645a83f..21acec2 100644 --- a/Helpers/HelperCreateNoteFiles.cs +++ b/Helpers/HelperCreateNoteFiles.cs @@ -1,3 +1,4 @@ +using Humanizer; using System.Globalization; using System.Text; @@ -114,9 +115,11 @@ internal static class HelperCreateNoteFiles string? directory; string[] segments; int descriptionKey = 2; + string[]? headerColumns; string destinationDirectory; DateTime dateTime = new(ticks); - StringBuilder stringBuilder = new(); + StringBuilder attributes = new(); + StringBuilder keyValuePairLinks = new(); string csvHeader = "type,title,description,links,body"; string tsvHeader = "type\ttitle\tdescription\tlinks\tbody"; int expectedCount = csvHeader.Length - csvHeader.Replace(",", string.Empty).Length + 1; @@ -124,6 +127,7 @@ internal static class HelperCreateNoteFiles { csv = false; tsv = false; + headerColumns = null; directory = Path.GetDirectoryName(importFile); if (directory is null) continue; @@ -132,10 +136,16 @@ internal static class HelperCreateNoteFiles { if (i == 0) { - if (lines[i] == csvHeader) + if (lines[i].StartsWith(csvHeader)) + { (csv, tsv) = (true, false); - else if (lines[i] == tsvHeader) + headerColumns = lines[i].Split(','); + } + else if (lines[i].StartsWith(tsvHeader)) + { (csv, tsv) = (false, true); + headerColumns = lines[i].Split('\t'); + } else break; continue; @@ -146,9 +156,10 @@ internal static class HelperCreateNoteFiles columns = lines[i].Split('\t'); else continue; - if (columns.Length != expectedCount) + if (columns.Length < expectedCount) continue; - _ = stringBuilder.Clear(); + _ = attributes.Clear(); + _ = keyValuePairLinks.Clear(); title = columns[titleKey].Trim(); linkText = columns[linksKey].Trim(); type = columns[typeKey].Trim().ToLower().Replace(' ', '-'); @@ -156,13 +167,22 @@ internal static class HelperCreateNoteFiles links = Array.Empty(); else links = linkText.Split(';', StringSplitOptions.RemoveEmptyEntries); + if (headerColumns is not null && columns.Length > expectedCount) + { + for (int j = expectedCount; j < columns.Length; j++) + { + if (headerColumns.Length <= j) + continue; + _ = attributes.AppendLine($"{headerColumns[j].Trim().Camelize()}: '{columns[j].Trim()}'"); + } + } foreach (string link in links) { segments = link.Split(':'); if (segments.Length == 1) - _ = stringBuilder.AppendLine($"- [[{segments.First()}]]"); + _ = keyValuePairLinks.AppendLine($"- [[{segments.First()}]]"); else if (segments.Length == 2) - _ = stringBuilder.AppendLine($"- [{segments.First()}]({segments.Last()})"); + _ = keyValuePairLinks.AppendLine($"- [{segments.First()}]({segments.Last()})"); else continue; } @@ -172,20 +192,23 @@ internal static class HelperCreateNoteFiles file = Path.Combine(destinationDirectory, $"{title.ToLower().Replace(' ', '-')}.md"); File.WriteAllLines(file, new string[] { - "---", - $"type: '{type}'", - $"title: '{title}'", - $"description: '{columns[descriptionKey].Trim()}'", - $"created: {dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}", - $"updated: {dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}", - "---", - string.Empty, - $"# {title}", - string.Empty, - stringBuilder.ToString(), - string.Empty, - columns[bodyKey].Trim(), - string.Empty, + "---", + $"type: '{type}'", + $"title: '{title}'", + $"description: '{columns[descriptionKey].Trim()}'", + $"created: {dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}", + $"updated: {dateTime:yyyy-MM-ddTHH:mm:ss.fffZ}", + attributes.ToString(), + "---", + string.Empty, + $"# {title}", + string.Empty, + keyValuePairLinks.ToString(), + string.Empty, + $"## Comment {dateTime:yyyy-MM-dd}", + string.Empty, + columns[bodyKey].Trim(), + string.Empty, }); } } @@ -194,8 +217,8 @@ internal static class HelperCreateNoteFiles internal static void CreateNoteFiles(string argsZero) { long ticks = DateTime.Now.Ticks; - CleanExistingFiles(argsZero, ticks); List importFiles = new(); + CleanExistingFiles(argsZero, ticks); importFiles.AddRange(Directory.GetFiles(argsZero, "*.csv", SearchOption.TopDirectoryOnly)); importFiles.AddRange(Directory.GetFiles(argsZero, "*.tsv", SearchOption.TopDirectoryOnly)); if (!importFiles.Any()) diff --git a/Helpers/HelperMarkdown.cs b/Helpers/HelperMarkdown.cs index 90081a9..56abe9a 100644 --- a/Helpers/HelperMarkdown.cs +++ b/Helpers/HelperMarkdown.cs @@ -153,8 +153,6 @@ internal static partial class HelperMarkdown List results = new(); foreach ((MarkdownFile markdownFile, string[] lines) in collection) { - if (markdownFile.FileName == "board.md") - continue; if (!lines.Any()) continue; results.Clear();