From ec3afd2f965f43dfb6eebbe36d72607810381fac Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sun, 16 Jul 2023 23:38:05 -0700 Subject: [PATCH] EC Documentation --- .kanbn/board.md | Bin 0 -> 4198 bytes Helpers/HelperCreateNoteFiles.cs | 67 +++++++++++++++++++++---------- Helpers/HelperMarkdown.cs | 2 - 3 files changed, 45 insertions(+), 24 deletions(-) create mode 100644 .kanbn/board.md diff --git a/.kanbn/board.md b/.kanbn/board.md new file mode 100644 index 0000000000000000000000000000000000000000..6b41138721ca7089750e671a4e2c0146326d4f4a GIT binary patch literal 4198 zcmd^CO-sW-5S_E&e^~IUr0PMD60j9TP$**Y9MhyNP16#qqE>&p`rd3qi2cArwIN|y zo9uk-?7o>d@$0iL4>FM#i6jtLwq;9vN$~7pHIR-NdBgN&1dS0SCwS}P*Mp6bceS8? zq!xYX#PGPt>O%bnkf(Naaprbs1XE}<;Ln$V?%KsW*KXmxgJ}vp80V#)v4!)F^sWM& zl6OMcnch%P;1g`-cBh(2yrI3^u(y_9E8^R#I9JJvc$WW+iFcFM{Ljo|Hk?Zz)kGd5 z`;4UrULb=+x;{W%)#V-%11@p#oM$gr4y1;8h@7g)k^Vh~mNTc9_cG6D^zA5v<(baK z&Wv-}pzH&qp|&0v%}5imCy3xtS(CBffI&k{?i)iw#-LR`s!g12*}2xSz8d*;?C{q< zeuI1qnLD0g&7NwI!D&Zj*Y(k9ZQo>$hmbMnDPbQ8v9_yg>?SdEja+N5r7z|V>w)z_ zs|0yNjU7x|H_RulSkLlC4k*UDM{)j+AvDX0cgDcgME(xQ4={~fDI@cXCCvfycmgT^ tr+HRB$aKn-4b?#Y6gaXEJD6>B{0`8y{XTnQPiCiH+{?>^xvhJP{5MWl(QE(! literal 0 HcmV?d00001 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();