Skip to content

Commit 2e805c3

Browse files
authored
Fix cross-repo redirect target paths (#1522)
1 parent 64defe5 commit 2e805c3

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/tooling/docs-assembler/Building/AssemblerBuilder.cs

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ await OutputRedirectsAsync(redirects
100100
await Task.WhenAll(tasks);
101101
}
102102

103-
private static void CollectRedirects(
103+
private void CollectRedirects(
104104
Dictionary<string, string> allRedirects,
105105
IReadOnlyDictionary<string, LinkRedirect> redirects,
106106
string repository,
@@ -121,11 +121,23 @@ ICrossLinkResolver linkResolver
121121
allRedirects[Resolve(k)] = Resolve(t);
122122
}
123123
}
124-
string Resolve(string relativeMarkdownPath)
124+
string Resolve(string path)
125125
{
126-
var uri = linkResolver.UriResolver.Resolve(new Uri($"{repository}://{relativeMarkdownPath}"),
127-
PublishEnvironmentUriResolver.MarkdownPathToUrlPath(relativeMarkdownPath));
128-
return uri.AbsolutePath;
126+
Uri? uri;
127+
if (Uri.IsWellFormedUriString(path, UriKind.Absolute)) // Cross-repo links
128+
{
129+
_ = linkResolver.TryResolve(
130+
(e) => _logger.LogError("An error occurred while resolving cross-link {Path}: {Error}", path, e),
131+
new Uri(path),
132+
out uri);
133+
}
134+
else // Relative links
135+
{
136+
uri = linkResolver.UriResolver.Resolve(new Uri($"{repository}://{path}"),
137+
PublishEnvironmentUriResolver.MarkdownPathToUrlPath(path));
138+
}
139+
140+
return uri?.AbsolutePath ?? string.Empty;
129141
}
130142
}
131143

0 commit comments

Comments
 (0)