Skip to content

Commit 1d0ba78

Browse files
committed
fix navigation validation for clashes
1 parent 42cf5c0 commit 1d0ba78

File tree

3 files changed

+24
-5
lines changed

3 files changed

+24
-5
lines changed

config/navigation.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
phantoms:
99
- toc: elasticsearch://reference
1010
- toc: docs-content://release-notes
11+
- toc: docs-content://release-notes/elasticsearch-clients
12+
- toc: docs-content://release-notes/apm-agents
1113
- toc: docs-content://
1214
- toc: cloud://release-notes
1315

src/services/Elastic.Documentation.Assembler/Links/PublishEnvironmentUriResolver.cs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,7 @@ public string[] ResolveToSubPaths(Uri crossLinkUri, string path)
141141
var mapping = FindBestMatchForSource(crossLinkUri);
142142

143143
if (mapping == null)
144-
{
145-
// No mapping found - return the path as-is
146-
return [path];
147-
}
144+
return [];
148145

149146
// Get the source prefix to calculate the relative path
150147
var sourcePrefix = $"{mapping.Source.Host}/{mapping.Source.AbsolutePath.TrimStart('/')}".Trim('/');

src/services/Elastic.Documentation.Assembler/Navigation/NavigationPrefixChecker.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,16 +92,36 @@ private async Task FetchAndValidateCrossLinks(IDiagnosticsCollector collector, s
9292
var dictionary = new Dictionary<string, SeenPaths>();
9393
if (!string.IsNullOrEmpty(updateRepository) && updateReference is not null)
9494
crossLinks = crossLinkResolver.UpdateLinkReference(updateRepository, updateReference);
95+
96+
var skippedPhantoms = 0;
9597
foreach (var (repository, linkReference) in crossLinks.LinkReferences)
9698
{
9799
if (!_repositories.Contains(repository))
98100
continue;
99101

102+
_logger.LogInformation("Validating '{Repository}'", repository);
100103
// Todo publish all relative folders as part of the link reference
101104
// That way we don't need to iterate over all links and find all permutations of their relative paths
102105
foreach (var (relativeLink, _) in linkReference.Links)
103106
{
104-
var navigationPaths = _uriResolver.ResolveToSubPaths(new Uri($"{repository}://{relativeLink}"), relativeLink);
107+
var crossLink = new Uri($"{repository}://{relativeLink.TrimEnd('/')}");
108+
var navigationPaths = _uriResolver.ResolveToSubPaths(crossLink, relativeLink);
109+
if (navigationPaths.Length == 0)
110+
{
111+
var path = relativeLink.Split('/').SkipLast(1);
112+
var pathUri = new Uri($"{repository}://{string.Join('/', path)}");
113+
114+
var baseOfAPhantom = _phantoms.Any(p => p == pathUri);
115+
if (baseOfAPhantom)
116+
{
117+
skippedPhantoms++;
118+
if (skippedPhantoms > _phantoms.Count * 3)
119+
collector.EmitError(repository, $"Too many items are being marked as part of a phantom this looks like a bug. ({skippedPhantoms})");
120+
continue;
121+
}
122+
collector.EmitError(repository, $"'Can not validate '{crossLink}' it's not declared in any link reference nor is it a phantom");
123+
continue;
124+
}
105125
foreach (var navigationPath in navigationPaths)
106126
{
107127
if (dictionary.TryGetValue(navigationPath, out var seen))

0 commit comments

Comments
 (0)