From c64143f320950bd7b38be006b71415d133abb86e Mon Sep 17 00:00:00 2001 From: Mike Phares Date: Sun, 2 Feb 2025 14:12:21 -0700 Subject: [PATCH] Inner links --- .gitignore | 2 ++ .vscode/tasks.json | 31 ++++++++++--------- src/KanbnToQuartz/Services/CopyService.cs | 37 +++++++++++++++++++---- 3 files changed, 49 insertions(+), 21 deletions(-) diff --git a/.gitignore b/.gitignore index 3abb96b..136928a 100644 --- a/.gitignore +++ b/.gitignore @@ -335,3 +335,5 @@ ASALocalRun/ .vscode/.UserSecrets/secrets.json .vscode/jsonl/* +.vscode/.year-season-source +.vscode/.year-season-destination \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json index 457b408..fe2765a 100644 --- a/.vscode/tasks.json +++ b/.vscode/tasks.json @@ -89,8 +89,8 @@ "problemMatcher": "$msCompile" }, { - "label": "dockerLogin", - "command": "docker", + "label": "podmanLogin", + "command": "podman", "type": "process", "args": [ "login", @@ -99,19 +99,20 @@ "problemMatcher": "$msCompile" }, { - "label": "dockerBuild", - "command": "docker", + "label": "podmanBuild", + "command": "podman", "type": "process", "args": [ "build", "-t", - "kanbn-to-quartz" + "kanbn-to-quartz", + "." ], "problemMatcher": "$msCompile" }, { - "label": "dockerImageList", - "command": "docker", + "label": "podmanImageList", + "command": "podman", "type": "process", "args": [ "image", @@ -120,8 +121,8 @@ "problemMatcher": "$msCompile" }, { - "label": "dockerRun", - "command": "docker", + "label": "podmanRun", + "command": "podman", "type": "process", "args": [ "run", @@ -129,24 +130,24 @@ "5001:5001", "--name", "kanbn-to-quartz-api-001", - "cb5bbb2e84e7" + "a3de856b5731" ], "problemMatcher": "$msCompile" }, { - "label": "dockerTag", - "command": "docker", + "label": "podmanTag", + "command": "podman", "type": "process", "args": [ "tag", - "b84c1f73de01", + "a3de856b5731", "gitea.phares.duckdns.org:443/phares3757/kanbn-to-quartz:latest" ], "problemMatcher": "$msCompile" }, { - "label": "dockerPush", - "command": "docker", + "label": "podmanPush", + "command": "podman", "type": "process", "args": [ "push", diff --git a/src/KanbnToQuartz/Services/CopyService.cs b/src/KanbnToQuartz/Services/CopyService.cs index d7457a0..2b637b7 100644 --- a/src/KanbnToQuartz/Services/CopyService.cs +++ b/src/KanbnToQuartz/Services/CopyService.cs @@ -19,6 +19,8 @@ public class CopyService string path; string fileB; string pathB; + string pathC; + string pathD; string textB; string? text; Record record; @@ -26,6 +28,7 @@ public class CopyService string[] lines; string pathName; string directory; + string[] segments; string destination; string relativePath; string directoryName; @@ -55,13 +58,33 @@ public class CopyService relativeDirectory = Path.GetRelativePath(sourceDirectoryName, directoryName); for (int i = 0; i < lines.Length; i++) { - if (!lines[i].StartsWith(textBFindReplace)) + if (!lines[i].Contains(textBFindReplace)) continue; - path = lines[i].Substring(textBFindReplace.Length, lines[i].Length - 1 - textBFindReplace.Length); - pathB = string.IsNullOrEmpty(directoryBFindReplace[0]) ? path : path.Replace(directoryBFindReplace[0], directoryBFindReplace[1]); - pathName = Path.GetFileName(pathB); - relativePath = Path.GetRelativePath(sourceDirectoryName, pathB); - lines[i] = $"- [{pathName}]({relativePath})"; + if (!lines[i].EndsWith(')') && !lines[i].EndsWith(")~~")) + continue; + if (lines[i].StartsWith(textBFindReplace)) + path = lines[i].Substring(textBFindReplace.Length, lines[i].Length - 1 - textBFindReplace.Length); + else + { + segments = lines[i].Split("~~"); + if (segments.Length < 2 || !segments[1].StartsWith(textBFindReplace)) + continue; + path = segments[1].Substring(textBFindReplace.Length, segments[1].Length - 1 - textBFindReplace.Length); + } + if (string.IsNullOrEmpty(directoryBFindReplace[0])) + { + pathD = path; + pathName = Path.GetFileName(path); + } + else + { + pathB = path.Replace(directoryBFindReplace[0], directoryBFindReplace[1]); + pathC = directoryBFindReplace[1][0] != '/' ? pathB : pathB.Replace('\\', '/'); + pathName = Path.GetFileName(pathC); + pathD = $"{pathC}{directoryFindReplace[1]}{pathName}"; + } + relativePath = Path.GetRelativePath(sourceDirectoryName, pathD); + lines[i] = lines[i].Replace($"{textBFindReplace}{path}", $"- [{pathName}]({relativePath}"); } textB = string.Join(Environment.NewLine, lines); text = textB.Replace(textFindReplace[0], textFindReplace[1].Replace("%", relativeDirectory)); @@ -91,6 +114,8 @@ public class CopyService public void CopyDirectory() { + if (!Directory.Exists(_AppSettings.Source)) + _ = Directory.CreateDirectory(_AppSettings.Source); if (Directory.Exists(_AppSettings.Destination)) Directory.Delete(_AppSettings.Destination, recursive: true); ReadOnlyCollection records = GetRecords(_AppSettings);