diff --git a/src/Elastic.Markdown/Extensions/CliReference/CliMarkdownGenerator.cs b/src/Elastic.Markdown/Extensions/CliReference/CliMarkdownGenerator.cs index 0b718330e8..d260b30f8b 100644 --- a/src/Elastic.Markdown/Extensions/CliReference/CliMarkdownGenerator.cs +++ b/src/Elastic.Markdown/Extensions/CliReference/CliMarkdownGenerator.cs @@ -46,7 +46,7 @@ public static string RootPage(CliSchema schema, CliSupplementalDoc? supplemental _ = sb.AppendLine("## Namespaces"); _ = sb.AppendLine(); foreach (var ns in schema.Namespaces) - AppendPageCard(sb, ns.Segment, $"./{ns.Segment}/index.md", ns.Summary); + AppendPageCard(sb, ns.Segment, $"./{ns.Segment}", ns.Summary); } if (schema.Environment?.Variables is { Count: > 0 } envVars) @@ -129,7 +129,7 @@ public static string NamespacePage( { var depth = fullPath?.Length ?? 1; var upPrefix = string.Concat(Enumerable.Repeat("../", depth)); - var links = nsAliases.Select(a => $"[`{binaryName ?? a} {a}`]({upPrefix}{a}/index.md)"); + var links = nsAliases.Select(a => $"[`{binaryName ?? a} {a}`]({upPrefix}{a})"); _ = sb.AppendLine($"Also accessible as {string.Join(", ", links)}."); _ = sb.AppendLine(); } @@ -159,7 +159,7 @@ public static string NamespacePage( _ = sb.AppendLine("## Sub-namespaces"); _ = sb.AppendLine(); foreach (var sub in subNamespaces) - AppendPageCard(sb, sub.Segment, $"./{sub.Segment}/index.md", sub.Summary); + AppendPageCard(sb, sub.Segment, $"./{sub.Segment}", sub.Summary); } var options = ns.Options ?? []; diff --git a/src/Elastic.Markdown/Extensions/CliReference/CliRootFile.cs b/src/Elastic.Markdown/Extensions/CliReference/CliRootFile.cs index 1eefadd2b7..739409b609 100644 --- a/src/Elastic.Markdown/Extensions/CliReference/CliRootFile.cs +++ b/src/Elastic.Markdown/Extensions/CliReference/CliRootFile.cs @@ -30,8 +30,8 @@ public CliRootFile( { _schema = schema; _supplementalDoc = supplementalDoc; - _title = string.IsNullOrWhiteSpace(title) ? schema.Name : title; - _navigationTitle = string.IsNullOrWhiteSpace(navigationTitle) ? $"{schema.Name} CLI" : navigationTitle; + _title = string.IsNullOrWhiteSpace(title) ? schema.Name : title.Trim(); + _navigationTitle = string.IsNullOrWhiteSpace(navigationTitle) ? $"{schema.Name} CLI" : navigationTitle.Trim(); Title = _title; } diff --git a/src/Elastic.Markdown/Myst/Directives/PageCard/PageCardBlock.cs b/src/Elastic.Markdown/Myst/Directives/PageCard/PageCardBlock.cs index 4cdc9db58f..810341d6c2 100644 --- a/src/Elastic.Markdown/Myst/Directives/PageCard/PageCardBlock.cs +++ b/src/Elastic.Markdown/Myst/Directives/PageCard/PageCardBlock.cs @@ -55,6 +55,11 @@ public override void FinalizeAndValidate(ParserContext context) : relativeToSource; ResolvedUrl = "/" + withoutExtension.Replace('\\', '/'); + + // Apply URL path prefix so links work in preview/sub-path deployments (same logic as DiagnosticLinkInlineParser) + var urlPathPrefix = context.Build.UrlPathPrefix ?? string.Empty; + if (!string.IsNullOrWhiteSpace(urlPathPrefix) && !ResolvedUrl.StartsWith(urlPathPrefix, StringComparison.OrdinalIgnoreCase)) + ResolvedUrl = $"{urlPathPrefix.TrimEnd('/')}{ResolvedUrl}"; } [GeneratedRegex(@"^\[([^\]]+)\]\(([^)]+)\)$")]