Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 14 additions & 3 deletions src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,12 @@ protected override void Write(HtmlRenderer renderer, LinkInline link)

if (link.Url?.StartsWith('/') == true)
{
var currentRootNavigation = link.GetData(nameof(MarkdownFile.NavigationRoot)) as INavigationGroup;
var targetRootNavigation = link.GetData($"Target{nameof(MarkdownFile.NavigationRoot)}") as INavigationGroup;
// var currentRootNavigation = link.GetData(nameof(MarkdownFile.NavigationRoot)) as INavigationGroup;
// var targetRootNavigation = link.GetData($"Target{nameof(MarkdownFile.NavigationRoot)}") as INavigationGroup;
_ = renderer.Write(" hx-get=\"");
_ = renderer.WriteEscapeUrl(url);
_ = renderer.Write('"');
_ = renderer.Write($" hx-select-oob=\"{Htmx.GetHxSelectOob(currentRootNavigation?.Id == targetRootNavigation?.Id)}\"");
_ = renderer.Write($" hx-select-oob=\"{Htmx.GetHxSelectOob(HasSameTopLevelSegment(currentUrl, link.Url))}\"");
_ = renderer.Write($" hx-swap=\"{Htmx.HxSwap}\"");
_ = renderer.Write($" hx-push-url=\"{Htmx.HxPushUrl}\"");
_ = renderer.Write($" hx-indicator=\"{Htmx.HxIndicator}\"");
Expand Down Expand Up @@ -74,6 +74,17 @@ protected override void Write(HtmlRenderer renderer, LinkInline link)
else
base.Write(renderer, link);
}

private static bool HasSameTopLevelSegment(string currentUrl, string targetUrl)
{
var currentUrlSegments = currentUrl.Split('/', StringSplitOptions.RemoveEmptyEntries);
var targetUrlSegments = targetUrl.Split('/', StringSplitOptions.RemoveEmptyEntries);

if (currentUrlSegments.Length == 0 || targetUrlSegments.Length == 0)
return false;

return currentUrlSegments[0].Equals(targetUrlSegments[0], StringComparison.OrdinalIgnoreCase);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Isn't targetUrlSegments[0] always docs ?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah dang. we should add the /docs prefix also for local development.

}
}

public static class CustomLinkInlineRendererExtensions
Expand Down
Loading