in src/Elastic.Markdown/IO/DocumentationSet.cs [239:284]
private void ValidateRedirectsExists()
{
if (Configuration.Redirects is null || Configuration.Redirects.Count == 0)
return;
foreach (var redirect in Configuration.Redirects)
{
if (redirect.Value.To is not null)
ValidateExists(redirect.Key, redirect.Value.To, redirect.Value.Anchors);
else if (redirect.Value.Many is not null)
{
foreach (var r in redirect.Value.Many)
{
if (r.To is not null)
ValidateExists(redirect.Key, r.To, r.Anchors);
}
}
}
void ValidateExists(string from, string to, IReadOnlyDictionary<string, string?>? valueAnchors)
{
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
to = to.Replace('/', Path.DirectorySeparatorChar);
if (!FlatMappedFiles.TryGetValue(to, out var file))
{
Context.EmitError(Configuration.SourceFile, $"Redirect {from} points to {to} which does not exist");
return;
}
if (file is not MarkdownFile markdownFile)
{
Context.EmitError(Configuration.SourceFile, $"Redirect {from} points to {to} which is not a markdown file");
return;
}
if (valueAnchors is null or { Count: 0 })
return;
markdownFile.AnchorRemapping =
markdownFile.AnchorRemapping?
.Concat(valueAnchors)
.DistinctBy(kv => kv.Key)
.ToDictionary(kv => kv.Key, kv => kv.Value) ?? valueAnchors;
}
}