From 7e2edbead7aa3a6abf61d7cae9e9ce5ddd454d24 Mon Sep 17 00:00:00 2001 From: Felipe Cotti Date: Fri, 4 Jul 2025 13:31:30 -0300 Subject: [PATCH] Fix cross-repo redirect target paths --- .../Building/AssemblerBuilder.cs | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/tooling/docs-assembler/Building/AssemblerBuilder.cs b/src/tooling/docs-assembler/Building/AssemblerBuilder.cs index f43baa9d7..393f89f65 100644 --- a/src/tooling/docs-assembler/Building/AssemblerBuilder.cs +++ b/src/tooling/docs-assembler/Building/AssemblerBuilder.cs @@ -100,7 +100,7 @@ await OutputRedirectsAsync(redirects await Task.WhenAll(tasks); } - private static void CollectRedirects( + private void CollectRedirects( Dictionary allRedirects, IReadOnlyDictionary redirects, string repository, @@ -121,11 +121,23 @@ ICrossLinkResolver linkResolver allRedirects[Resolve(k)] = Resolve(t); } } - string Resolve(string relativeMarkdownPath) + string Resolve(string path) { - var uri = linkResolver.UriResolver.Resolve(new Uri($"{repository}://{relativeMarkdownPath}"), - PublishEnvironmentUriResolver.MarkdownPathToUrlPath(relativeMarkdownPath)); - return uri.AbsolutePath; + Uri? uri; + if (Uri.IsWellFormedUriString(path, UriKind.Absolute)) // Cross-repo links + { + _ = linkResolver.TryResolve( + (e) => _logger.LogError("An error occurred while resolving cross-link {Path}: {Error}", path, e), + new Uri(path), + out uri); + } + else // Relative links + { + uri = linkResolver.UriResolver.Resolve(new Uri($"{repository}://{path}"), + PublishEnvironmentUriResolver.MarkdownPathToUrlPath(path)); + } + + return uri?.AbsolutePath ?? string.Empty; } }