Write index.yml.md
Helper to diff video files Move matches from directory Bug fix for DirectoryToISO Find replace instead of remove Rename Directory Amazon Immich Person PersonKeyToName PullIconsForBLM New links
This commit is contained in:
@ -33,7 +33,7 @@ internal static partial class HelperKanbanMetadata
|
||||
}
|
||||
|
||||
private static void TestParamCases()
|
||||
{
|
||||
{ // cSpell:disable
|
||||
if (GetParamCase("PascalCase") != "pascal-case")
|
||||
throw new Exception("PascalCase");
|
||||
if (GetParamCase("camelCase") != "camel-case")
|
||||
@ -68,7 +68,7 @@ internal static partial class HelperKanbanMetadata
|
||||
throw new Exception("יקספּערמענאַל פּרובירן");
|
||||
if (GetParamCase("я надеюсь, что это сработает") != "я-надеюсь-что-это-сработает")
|
||||
throw new Exception("я надеюсь, что это сработает");
|
||||
}
|
||||
} // cSpell:restore
|
||||
|
||||
private static List<Record> GetCollectionFromIndex(string sourceDirectory, ReadOnlyCollection<string> lines)
|
||||
{
|
||||
@ -105,38 +105,94 @@ internal static partial class HelperKanbanMetadata
|
||||
private static void WriteKanbanBoardFile(string directory, List<Record> records, string h1)
|
||||
{
|
||||
string? last = null;
|
||||
List<string> lines = [h1];
|
||||
List<string> results = [h1];
|
||||
foreach (Record record in records)
|
||||
{
|
||||
if (last is null || record.Group != last)
|
||||
{
|
||||
lines.Add(string.Empty);
|
||||
lines.Add($"## {record.Group}");
|
||||
lines.Add(string.Empty);
|
||||
results.Add(string.Empty);
|
||||
results.Add($"## {record.Group}");
|
||||
results.Add(string.Empty);
|
||||
}
|
||||
lines.Add($"- [ ] {Path.GetFileNameWithoutExtension(record.FileInfo.Name)}");
|
||||
results.Add($"- [ ] {Path.GetFileNameWithoutExtension(record.FileInfo.Name)}");
|
||||
last = record.Group;
|
||||
}
|
||||
File.WriteAllLines(Path.Combine(directory, "index.knb.md"), lines);
|
||||
string file = Path.Combine(directory, "index.knb.md");
|
||||
if (File.Exists(file))
|
||||
{
|
||||
string allText = File.ReadAllText(file);
|
||||
if (string.Join(Environment.NewLine, results) == allText)
|
||||
results.Clear();
|
||||
}
|
||||
if (results.Count > 0)
|
||||
File.WriteAllText(file, string.Join(Environment.NewLine, results));
|
||||
}
|
||||
|
||||
internal static void SetMetadata(string sourceDirectory, string indexFile)
|
||||
private static void WriteKanbanBoardYmlView(string directory, List<Record> records, string kanbanIndexH1)
|
||||
{
|
||||
List<string> results = [kanbanIndexH1, string.Empty];
|
||||
string h1;
|
||||
TimeSpan timeSpan;
|
||||
List<string> lines;
|
||||
LineNumber lineNumber;
|
||||
Record[] sorted = (from l in records orderby l.GroupCount, l.FileInfo.LastWriteTime descending select l).ToArray();
|
||||
foreach (Record record in sorted)
|
||||
{
|
||||
if (record.ItemLineNumber == 0)
|
||||
throw new NotSupportedException();
|
||||
(lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(record.FileInfo);
|
||||
if (lines.Count == 0)
|
||||
continue;
|
||||
timeSpan = new(record.FileInfo.LastWriteTime.Ticks - record.FileInfo.CreationTime.Ticks);
|
||||
h1 = lineNumber.H1 is null ? Path.GetFileNameWithoutExtension(record.FileInfo.Name) : lines[lineNumber.H1.Value];
|
||||
results.Add($"#{h1}");
|
||||
results.Add(string.Empty);
|
||||
results.Add("```yaml");
|
||||
results.Add($"CreationTime: {record.FileInfo.CreationTime:yyyy-MM-dd}");
|
||||
results.Add($"LastWriteTime: {record.FileInfo.LastWriteTime:yyyy-MM-dd}");
|
||||
results.Add($"TotalDays: {Math.Round(timeSpan.TotalDays, 2)}");
|
||||
if (lineNumber.FrontMatterYamlEnd is not null && lines.Count >= lineNumber.FrontMatterYamlEnd.Value)
|
||||
{
|
||||
for (int i = 0; i < lineNumber.FrontMatterYamlEnd; i++)
|
||||
{
|
||||
if (lines[i] == "---")
|
||||
continue;
|
||||
results.Add(lines[i]);
|
||||
}
|
||||
}
|
||||
results.Add($"status: \"{record.GroupCount}-{record.Group}\"");
|
||||
results.Add("```");
|
||||
results.Add(string.Empty);
|
||||
}
|
||||
string file = Path.Combine(directory, "index.yml.md");
|
||||
if (File.Exists(file))
|
||||
{
|
||||
string allText = File.ReadAllText(file);
|
||||
if (string.Join(Environment.NewLine, results) == allText)
|
||||
results.Clear();
|
||||
}
|
||||
if (results.Count > 0)
|
||||
File.WriteAllText(file, string.Join(Environment.NewLine, results));
|
||||
}
|
||||
|
||||
internal static void SetMetadata(string sourceDirectory, ReadOnlyCollection<string> kanbanIndexFileLines, LineNumber kanbanIndexFileLineNumber, ReadOnlyCollection<string> gitOthersModifiedAndDeletedExcludingStandardFiles)
|
||||
{
|
||||
bool? match;
|
||||
bool gitCheck;
|
||||
string? paramCase;
|
||||
string statusLine;
|
||||
List<string> lines;
|
||||
LineNumber lineNumber;
|
||||
FileInfo fileInfo = new(indexFile);
|
||||
string? directory = Path.GetDirectoryName(sourceDirectory);
|
||||
(lines, lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(fileInfo);
|
||||
ReadOnlyCollection<string> indexFileLines = new(lines);
|
||||
List<Record> records = GetCollectionFromIndex(sourceDirectory, indexFileLines);
|
||||
if (directory is not null && lineNumber.H1 is not null)
|
||||
List<Record> records = GetCollectionFromIndex(sourceDirectory, kanbanIndexFileLines);
|
||||
if (directory is not null && kanbanIndexFileLineNumber.H1 is not null)
|
||||
{
|
||||
string checkDirectory = Path.Combine(directory, ".vscode", "helper");
|
||||
if (Directory.Exists(checkDirectory))
|
||||
WriteKanbanBoardFile(checkDirectory, records, indexFileLines[lineNumber.H1.Value]);
|
||||
{
|
||||
WriteKanbanBoardFile(checkDirectory, records, kanbanIndexFileLines[kanbanIndexFileLineNumber.H1.Value]);
|
||||
WriteKanbanBoardYmlView(checkDirectory, records, kanbanIndexFileLines[kanbanIndexFileLineNumber.H1.Value]);
|
||||
}
|
||||
}
|
||||
foreach (Record record in records)
|
||||
{
|
||||
@ -160,6 +216,9 @@ internal static partial class HelperKanbanMetadata
|
||||
continue;
|
||||
lines[lineNumber.Status.Value] = statusLine;
|
||||
}
|
||||
gitCheck = gitOthersModifiedAndDeletedExcludingStandardFiles.Contains(record.FileInfo.FullName);
|
||||
if (!gitCheck)
|
||||
continue;
|
||||
File.WriteAllLines(record.FileInfo.FullName, lines);
|
||||
}
|
||||
}
|
||||
@ -171,10 +230,14 @@ internal static partial class HelperKanbanMetadata
|
||||
if (!Directory.Exists(fullPath))
|
||||
_ = Directory.CreateDirectory(fullPath);
|
||||
string indexFile = Path.Combine(fullPath, "index.md");
|
||||
if (File.Exists(indexFile))
|
||||
SetMetadata(fullPath, indexFile);
|
||||
else
|
||||
if (!File.Exists(indexFile))
|
||||
logger.LogInformation("<{indexFile}> doesn't exist!", indexFile);
|
||||
else
|
||||
{
|
||||
FileInfo fileInfo = new(indexFile);
|
||||
(List<string> lines, LineNumber lineNumber) = HelperMarkdown.GetStatusAndFrontMatterYamlEndLineNumbers(fileInfo);
|
||||
SetMetadata(fullPath, new(lines), lineNumber, gitOthersModifiedAndDeletedExcludingStandardFiles: new([]));
|
||||
}
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user