Skip to content

Commit 5ca4d6e

Browse files
committed
fix cross links
1 parent 805101d commit 5ca4d6e

File tree

5 files changed

+15
-13
lines changed

5 files changed

+15
-13
lines changed

docs/testing/cross-links.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
# Cross Links
22

3-
[Elasticsearch](docs-content://index.md)
4-
5-
[Kibana][1]
3+
[docs-content](docs-content://index.md)
64

75
[1]: docs-content://index.md

src/Elastic.Documentation.Navigation/Elastic.Documentation.Navigation.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
<ItemGroup>
1010
<ProjectReference Include="..\Elastic.Documentation.Configuration\Elastic.Documentation.Configuration.csproj" />
11+
<ProjectReference Include="..\Elastic.Documentation.Links\Elastic.Documentation.Links.csproj" />
1112
</ItemGroup>
1213

1314
</Project>

src/Elastic.Documentation.Navigation/Isolated/Node/DocumentationSetNavigation.cs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
using System.IO.Abstractions;
77
using Elastic.Documentation.Configuration.DocSet;
88
using Elastic.Documentation.Extensions;
9+
using Elastic.Documentation.Links.CrossLinks;
910
using Elastic.Documentation.Navigation.Isolated.Leaf;
1011

1112
namespace Elastic.Documentation.Navigation.Isolated.Node;
@@ -22,18 +23,21 @@ public class DocumentationSetNavigation<TModel>
2223
where TModel : class, IDocumentationFile
2324
{
2425
private readonly IDocumentationFileFactory<TModel> _factory;
26+
private readonly ICrossLinkResolver _crossLinkResolver;
2527

2628
public DocumentationSetNavigation(
2729
DocumentationSetFile documentationSet,
2830
IDocumentationSetContext context,
2931
IDocumentationFileFactory<TModel> factory,
3032
IRootNavigationItem<INavigationModel, INavigationItem>? parent = null,
3133
IRootNavigationItem<INavigationModel, INavigationItem>? root = null,
32-
string? pathPrefix = null
34+
string? pathPrefix = null,
35+
ICrossLinkResolver? crossLinkResolver = null
3336
)
3437
{
3538
_context = context;
3639
_factory = factory;
40+
_crossLinkResolver = crossLinkResolver ?? NoopCrossLinkResolver.Instance;
3741
_pathPrefix = pathPrefix ?? string.Empty;
3842
// Initialize root properties
3943
_navigationRoot = root ?? this;
@@ -139,7 +143,7 @@ public DocumentationSetNavigation(
139143
public IReadOnlyCollection<INavigationItem> NavigationItems { get; private set; }
140144

141145
void IAssignableChildrenNavigation.SetNavigationItems(IReadOnlyCollection<INavigationItem> navigationItems) => SetNavigationItems(navigationItems);
142-
internal void SetNavigationItems(IReadOnlyCollection<INavigationItem> navigationItems)
146+
private void SetNavigationItems(IReadOnlyCollection<INavigationItem> navigationItems)
143147
{
144148
var indexNavigation = navigationItems.QueryIndex<TModel>(this, $"{PathPrefix}/index.md", out navigationItems);
145149
Index = indexNavigation;
@@ -280,19 +284,21 @@ INavigationHomeAccessor homeAccessor
280284
return fileNavigation;
281285
}
282286

283-
private INavigationItem CreateCrossLinkNavigation(
287+
private INavigationItem? CreateCrossLinkNavigation(
284288
CrossLinkRef crossLinkRef,
285289
int index,
286290
INodeNavigationItem<INavigationModel, INavigationItem>? parent,
287291
INavigationHomeAccessor homeAccessor
288292
)
289293
{
290294
var title = crossLinkRef.Title ?? crossLinkRef.CrossLinkUri.OriginalString;
291-
var model = new CrossLinkModel(crossLinkRef.CrossLinkUri, title);
295+
if (!_crossLinkResolver.TryResolve(s => _context.EmitError(_context.ConfigurationPath, s), crossLinkRef.CrossLinkUri, out var resolvedUri))
296+
return null;
297+
var model = new CrossLinkModel(resolvedUri, title);
292298

293299
return new CrossLinkNavigationLeaf(
294300
model,
295-
crossLinkRef.CrossLinkUri.OriginalString,
301+
resolvedUri.ToString(),
296302
crossLinkRef.Hidden,
297303
parent,
298304
homeAccessor

src/Elastic.Markdown/IO/DocumentationSet.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
using Elastic.Documentation.Links;
1414
using Elastic.Documentation.Links.CrossLinks;
1515
using Elastic.Documentation.Navigation;
16-
using Elastic.Documentation.Navigation.Isolated;
1716
using Elastic.Documentation.Navigation.Isolated.Leaf;
1817
using Elastic.Documentation.Navigation.Isolated.Node;
1918
using Elastic.Documentation.Site.Navigation;
@@ -22,7 +21,6 @@
2221
using Elastic.Markdown.IO.NewNavigation;
2322
using Elastic.Markdown.Myst;
2423
using Microsoft.Extensions.Logging;
25-
using YamlDotNet.Serialization.TypeInspectors;
2624

2725
namespace Elastic.Markdown.IO;
2826

@@ -77,7 +75,7 @@ ICrossLinkResolver linkResolver
7775
MarkdownParser = new MarkdownParser(context, resolver);
7876

7977
var fileFactory = new MarkdownFileFactory(context, MarkdownParser, EnabledExtensions);
80-
Navigation = new DocumentationSetNavigation<MarkdownFile>(context.ConfigurationYaml, context, fileFactory, pathPrefix: context.UrlPathPrefix);
78+
Navigation = new DocumentationSetNavigation<MarkdownFile>(context.ConfigurationYaml, context, fileFactory, null, null, context.UrlPathPrefix, CrossLinkResolver);
8179

8280
Name = Context.Git != GitCheckoutInformation.Unavailable
8381
? Context.Git.RepositoryName

src/services/Elastic.Documentation.Assembler/AssembleSources.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,7 @@ IReadOnlySet<Exporter> availableExporters
8686
AssembleContext = assembleContext;
8787
AssembleSets = checkouts
8888
.Where(c => c.Repository is { Skip: false })
89-
.Select(c => new AssemblerDocumentationSet(logFactory, assembleContext, c, crossLinkResolver, configurationContext,
90-
availableExporters))
89+
.Select(c => new AssemblerDocumentationSet(logFactory, assembleContext, c, crossLinkResolver, configurationContext, availableExporters))
9190
.ToDictionary(s => s.Checkout.Repository.Name, s => s)
9291
.ToFrozenDictionary();
9392
}

0 commit comments

Comments
 (0)