Skip to content

Commit 9bdbec0

Browse files
committed
It's working
1 parent 88a29ab commit 9bdbec0

File tree

7 files changed

+40
-8
lines changed

7 files changed

+40
-8
lines changed

src/Elastic.Documentation.Site/Elastic.Documentation.Site.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<Project Sdk="Microsoft.NET.Sdk.Razor">
1+
<Project Sdk="Microsoft.NET.Sdk.Razor">
22

33
<PropertyGroup>
44
<TargetFramework>net9.0</TargetFramework>
@@ -15,7 +15,7 @@
1515

1616
<ItemGroup>
1717
<ProjectReference Include="..\Elastic.Documentation\Elastic.Documentation.csproj" />
18-
<ProjectReference Include="..\Elastic.Documentation.Configuration\Elastic.Documentation.Configuration.csproj" />
18+
<ProjectReference Include="..\Elastic.Documentation.Configuration\Elastic.Documentation.Configuration.csproj" />
1919
</ItemGroup>
2020

2121
<ItemGroup>

src/Elastic.Markdown/IO/Navigation/ExternalLinkNavigationItem.cs renamed to src/Elastic.Documentation.Site/Navigation/ExternalLinkNavigationItem.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,17 @@
44

55
using Elastic.Documentation.Site.Navigation;
66

7-
namespace Elastic.Markdown.IO.Navigation;
7+
namespace Elastic.Documentation.Site.Navigation;
88

99
/// <summary>
1010
/// Navigation item representing an external URL in the TOC.
1111
/// </summary>
12-
public record ExternalLinkNavigationItem(string ExternalUrl, string Title, DocumentationGroup Group)
12+
public record ExternalLinkNavigationItem(string ExternalUrl, string Title, INodeNavigationItem<INavigationModel, INavigationItem> Parent, IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot)
1313
: INavigationItem
1414
{
15-
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; } = Group;
15+
public INodeNavigationItem<INavigationModel, INavigationItem>? Parent { get; set; } = Parent;
1616

17-
public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot { get; } = Group.NavigationRoot;
17+
public IRootNavigationItem<INavigationModel, INavigationItem> NavigationRoot { get; } = NavigationRoot;
1818

1919
public string Url => ExternalUrl;
2020

src/Elastic.Documentation.Site/Navigation/_TocTreeNav.cshtml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
@using Elastic.Documentation.Site.Navigation
2+
23
@inherits RazorSlice<NavigationTreeItem>
34
@{
45
var isTopLevel = Model.Level == 0;
@@ -89,4 +90,18 @@
8990
</a>
9091
</li>
9192
}
93+
else if (item is ExternalLinkNavigationItem ext)
94+
{
95+
<li class="flex group/li pr-8 @(isTopLevel ? "font-semibold mt-6" : "mt-4")">
96+
<a
97+
href="@ext.Url"
98+
target="_blank"
99+
rel="noopener noreferrer"
100+
class="sidebar-link grow group-[.current]/li:text-blue-elastic! flex items-center"
101+
>
102+
@ext.NavigationTitle
103+
<svg class="ml-1 inline w-4 h-4 text-grey-60" xmlns="http://www.w3.org/2000/svg" fill="none" viewBox="0 0 24 24" stroke="currentColor"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M14 3h7v7m0 0L10 21l-7-7 11-11z"/></svg>
104+
</a>
105+
</li>
106+
}
92107
}

src/Elastic.Markdown/IO/DocumentationSet.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
using Elastic.Markdown.Links.CrossLinks;
2020
using Elastic.Markdown.Myst;
2121
using Microsoft.Extensions.Logging;
22+
using ExternalLinkNavigationItem = Elastic.Documentation.Site.Navigation.ExternalLinkNavigationItem;
2223

2324
namespace Elastic.Markdown.IO;
2425

@@ -227,6 +228,10 @@ private void UpdateNavigationIndex(IReadOnlyCollection<INavigationItem> navigati
227228
documentationGroup.NavigationIndex = groupIndex;
228229
UpdateNavigationIndex(documentationGroup.NavigationItems, ref navigationIndex);
229230
break;
231+
case ExternalLinkNavigationItem ext:
232+
var linkIndex = Interlocked.Increment(ref navigationIndex);
233+
ext.NavigationIndex = linkIndex;
234+
break;
230235
default:
231236
Context.EmitError(Context.ConfigurationPath, $"Unhandled navigation item type: {item.GetType()}");
232237
break;

src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,9 @@
66
using Elastic.Documentation;
77
using Elastic.Documentation.Configuration;
88
using Elastic.Documentation.Configuration.TableOfContents;
9-
using Elastic.Markdown.IO.Navigation; // for ExternalLinkNavigationItem
109
using Elastic.Documentation.Extensions;
1110
using Elastic.Documentation.Site.Navigation;
11+
using ExternalLinkNavigationItem = Elastic.Documentation.Site.Navigation.ExternalLinkNavigationItem;
1212

1313
namespace Elastic.Markdown.IO.Navigation;
1414

@@ -181,7 +181,7 @@ void AddToNavigationItems(INavigationItem item, ref int fileIndex)
181181
}
182182
else if (tocItem is LinkReference extLink)
183183
{
184-
var nav = new ExternalLinkNavigationItem(extLink.Url, extLink.Title, this);
184+
var nav = new ExternalLinkNavigationItem(extLink.Url, extLink.Title, this, rootNavigationItem);
185185
AddToNavigationItems(nav, ref fileIndex);
186186
}
187187
else if (tocItem is FolderReference folder)

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ private static IReadOnlyCollection<INavigationItem> GetNavigationItems(IReadOnly
7676
result.AddRange(GetNavigationItems(group.NavigationItems));
7777
result.Add(group);
7878
break;
79+
case ExternalLinkNavigationItem link:
80+
// skip external links in sitemap
81+
continue;
7982
default:
8083
throw new Exception($"Unhandled navigation item type: {item.GetType()}");
8184
}

src/tooling/docs-assembler/Navigation/GlobalNavigation.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ private void UpdateParent(
8282
_ = allNavigationItems.Add(documentationGroup);
8383
UpdateParent(allNavigationItems, documentationGroup.NavigationItems, documentationGroup);
8484
break;
85+
case ExternalLinkNavigationItem extLink:
86+
if (parent is not null)
87+
extLink.Parent = parent;
88+
_ = allNavigationItems.Add(extLink);
89+
break;
8590
default:
8691
_navigationFile.EmitError($"Unhandled navigation item type: {item.GetType()}");
8792
break;
@@ -105,6 +110,10 @@ private void UpdateNavigationIndex(IReadOnlyCollection<INavigationItem> navigati
105110
documentationGroup.NavigationIndex = groupIndex;
106111
UpdateNavigationIndex(documentationGroup.NavigationItems, ref navigationIndex);
107112
break;
113+
case ExternalLinkNavigationItem extLink:
114+
var linkIndex = Interlocked.Increment(ref navigationIndex);
115+
extLink.NavigationIndex = linkIndex;
116+
break;
108117
default:
109118
_navigationFile.EmitError($"Unhandled navigation item type: {item.GetType()}");
110119
break;

0 commit comments

Comments
 (0)