in src/Elastic.Documentation.Configuration/Builder/RedirectFile.cs [48:82]
private static Dictionary<string, LinkRedirect>? ReadRedirects(YamlStreamReader reader, KeyValuePair<YamlNode, YamlNode> entry)
{
if (!reader.ReadObjectDictionary(entry, out var mapping))
return null;
var dictionary = new Dictionary<string, LinkRedirect>(StringComparer.OrdinalIgnoreCase);
foreach (var entryValue in mapping.Children)
{
if (entryValue.Key is not YamlScalarNode scalar || scalar.Value is null)
continue;
var key = scalar.Value;
if (entryValue.Value is YamlScalarNode)
{
var to = reader.ReadString(entryValue);
dictionary.Add(key,
!string.IsNullOrEmpty(to)
? to.StartsWith('!')
? new LinkRedirect { To = to.TrimStart('!'), Anchors = LinkRedirect.CatchAllAnchors }
: new LinkRedirect { To = to }
: new LinkRedirect { To = "index.md", Anchors = LinkRedirect.CatchAllAnchors }
);
continue;
}
if (!reader.ReadObjectDictionary(entryValue, out var valueMapping))
continue;
var linkRedirect = ReadLinkRedirect(reader, key, valueMapping);
if (linkRedirect is not null)
dictionary.Add(key, linkRedirect);
}
return dictionary;
}