Update Subtasks In Markdown Files
Better ISO support Only reviewing Files when comparing Extracted sections from UpdateSubTasksInMarkdownFiles
This commit is contained in:
@ -193,7 +193,7 @@ internal static partial class HelperMarkdown
|
||||
return result;
|
||||
}
|
||||
|
||||
private static ReadOnlyCollection<string> GetFromMatterYamlLines(List<string> lines, LineNumber lineNumber)
|
||||
private static ReadOnlyCollection<string> GetFromMatterYamlLines(ReadOnlyCollection<string> lines, LineNumber lineNumber)
|
||||
{
|
||||
List<string> results = [];
|
||||
if (lineNumber.FrontMatterYamlEnd is not null && lines.Count >= lineNumber.FrontMatterYamlEnd.Value)
|
||||
@ -307,7 +307,7 @@ internal static partial class HelperMarkdown
|
||||
return new(results);
|
||||
}
|
||||
|
||||
internal static (List<string>, LineNumber) GetStatusAndFrontMatterYamlEndLineNumbers(FileInfo fileInfo)
|
||||
internal static LineNumber GetLineNumbers(FileInfo fileInfo)
|
||||
{
|
||||
string line;
|
||||
int? h1LineNumber = null;
|
||||
@ -315,6 +315,8 @@ internal static partial class HelperMarkdown
|
||||
int? statusLineNumber = null;
|
||||
int? createdLineNumber = null;
|
||||
int? updatedLineNumber = null;
|
||||
int? progressLineNumber = null;
|
||||
int? completedLineNumber = null;
|
||||
int? frontMatterYamlEndLineNumber = null;
|
||||
Encoding? encoding = GetEncoding(fileInfo.FullName) ?? Encoding.Default;
|
||||
string[] lines = File.ReadAllLines(fileInfo.FullName, encoding);
|
||||
@ -350,6 +352,16 @@ internal static partial class HelperMarkdown
|
||||
updatedLineNumber = i;
|
||||
continue;
|
||||
}
|
||||
if (line.Length > 10 && line[..10] == "progress: ")
|
||||
{
|
||||
progressLineNumber = i;
|
||||
continue;
|
||||
}
|
||||
if (line.Length > 11 && line[..11] == "completed: ")
|
||||
{
|
||||
completedLineNumber = i;
|
||||
continue;
|
||||
}
|
||||
if (h1LineNumber is null && line.Length > 2 && line[0] == '#' && line[1] == ' ')
|
||||
{
|
||||
h1LineNumber = i;
|
||||
@ -357,12 +369,15 @@ internal static partial class HelperMarkdown
|
||||
}
|
||||
}
|
||||
LineNumber lineNumber = new(createdLineNumber,
|
||||
completedLineNumber,
|
||||
h1LineNumber,
|
||||
frontMatterYamlEndLineNumber,
|
||||
lines.AsReadOnly(),
|
||||
progressLineNumber,
|
||||
statusLineNumber,
|
||||
typeLineNumber,
|
||||
updatedLineNumber);
|
||||
return (lines.ToList(), lineNumber);
|
||||
return lineNumber;
|
||||
}
|
||||
|
||||
private static Dictionary<string, object> GetFromMatterYaml(ReadOnlyCollection<string> frontMatterYamlLines)
|
||||
@ -387,7 +402,7 @@ internal static partial class HelperMarkdown
|
||||
return results;
|
||||
}
|
||||
|
||||
private static ReadOnlyDictionary<string, object> GetFromMatterYaml(List<string> lines, LineNumber lineNumber)
|
||||
private static ReadOnlyDictionary<string, object> GetFromMatterYaml(ReadOnlyCollection<string> lines, LineNumber lineNumber)
|
||||
{
|
||||
Dictionary<string, object> results = [];
|
||||
#pragma warning disable IL3050
|
||||
@ -660,12 +675,12 @@ internal static partial class HelperMarkdown
|
||||
string key;
|
||||
string type;
|
||||
bool isKanbanIndex;
|
||||
List<string> lines;
|
||||
bool isWithinSource;
|
||||
bool isKanbanMarkdown;
|
||||
LineNumber lineNumber;
|
||||
MarkdownFile markdownFile;
|
||||
string fileNameWithoutExtension;
|
||||
ReadOnlyCollection<string> lines;
|
||||
ReadOnlyDictionary<string, object> frontMatterYaml;
|
||||
bool isGitOthersModifiedAndDeletedExcludingStandard;
|
||||
ReadOnlyCollection<FileInfo> files = GetFiles(appSettings, input);
|
||||
@ -678,7 +693,8 @@ internal static partial class HelperMarkdown
|
||||
isGitOthersModifiedAndDeletedExcludingStandard = gitOthersModifiedAndDeletedExcludingStandardFiles.Contains(fileInfo.FullName);
|
||||
if (!isWithinSource && results.ContainsKey(key))
|
||||
continue;
|
||||
(lines, lineNumber) = GetStatusAndFrontMatterYamlEndLineNumbers(fileInfo);
|
||||
lineNumber = GetLineNumbers(fileInfo);
|
||||
lines = lineNumber.Lines;
|
||||
fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileInfo.FullName);
|
||||
h1 = fileNameWithoutExtension.ToLower().Replace("%20", "-").Replace(' ', '-');
|
||||
frontMatterYaml = GetFromMatterYaml(lines, lineNumber);
|
||||
@ -690,7 +706,7 @@ internal static partial class HelperMarkdown
|
||||
continue;
|
||||
type = appSettings.DefaultNoteType;
|
||||
File.WriteAllLines(fileInfo.FullName, ["---", $"type: {type}\"", "---", string.Empty, $"# {h1}"]);
|
||||
lines = File.ReadAllLines(fileInfo.FullName).ToList();
|
||||
lines = File.ReadAllLines(fileInfo.FullName).AsReadOnly();
|
||||
}
|
||||
isKanbanMarkdown = fileInfo.Name.EndsWith(".knb.md");
|
||||
isKanbanIndex = fileNameWithoutExtension == "index" && type.StartsWith("kanb", StringComparison.OrdinalIgnoreCase);
|
||||
@ -1042,7 +1058,7 @@ internal static partial class HelperMarkdown
|
||||
}
|
||||
}
|
||||
|
||||
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, ReadOnlyCollection<string> lines, LineNumber lineNumber)
|
||||
{
|
||||
string type = lineNumber.Type is null ? appSettings.DefaultNoteType : lines[lineNumber.Type.Value][5..].Trim().Trim('"');
|
||||
string h1FromFile = lineNumber.H1 is null ? h1 : lines[lineNumber.H1.Value][2..];
|
||||
@ -1080,7 +1096,7 @@ internal static partial class HelperMarkdown
|
||||
createdLine = $"created: {creationDateTime.ToUniversalTime():yyyy-MM-ddTHH:mm:ss.fffZ}";
|
||||
updatedLine = $"updated: {markdownFile.LastWriteDateTime.ToUniversalTime():yyyy-MM-ddTHH:mm:ss.fffZ}";
|
||||
if (markdownFile.IsKanbanIndex)
|
||||
HelperKanbanMetadata.SetMetadata(markdownFile.Directory, new(lines), markdownFile.LineNumber, gitOthersModifiedAndDeletedExcludingStandardFiles);
|
||||
HelperKanbanMetadata.SetMetadata(markdownFile.Directory, markdownFile.LineNumber, gitOthersModifiedAndDeletedExcludingStandardFiles);
|
||||
if (markdownFile.LineNumber.FrontMatterYamlEnd is null)
|
||||
{
|
||||
if (markdownFile.LineNumber.H1 is not null)
|
||||
|
Reference in New Issue
Block a user