diff --git a/docs/_docset.yml b/docs/_docset.yml index 5a6c83126..9434bb0f6 100644 --- a/docs/_docset.yml +++ b/docs/_docset.yml @@ -9,10 +9,6 @@ subs: serverless-short: Serverless ece: "Elastic Cloud Enterprise" eck: "Elastic Cloud on Kubernetes" - -features: - primary-nav: false - toc: - file: index.md - hidden: developer-notes.md diff --git a/src/Elastic.Markdown/Assets/pages-nav.ts b/src/Elastic.Markdown/Assets/pages-nav.ts index a5864cde0..ba8b8ff21 100644 --- a/src/Elastic.Markdown/Assets/pages-nav.ts +++ b/src/Elastic.Markdown/Assets/pages-nav.ts @@ -15,9 +15,9 @@ function scrollCurrentNaviItemIntoView(nav: HTMLElement, delay: number) { const currentNavItem = $('.current', nav); expandAllParents(currentNavItem); setTimeout(() => { + if (currentNavItem && !isElementInViewport(currentNavItem)) { currentNavItem.scrollIntoView({ behavior: 'smooth', block: 'center' }); - window.scrollTo(0, 0); } }, delay); } @@ -36,7 +36,7 @@ export function initNav() { if (!pagesNav) { return; } - const navItems = $$('a[href="' + window.location.pathname + '"], a[href="' + window.location.pathname + '/"]', pagesNav); + const navItems = $$('a[href="' + window.location.pathname + '"]', pagesNav); navItems.forEach(el => { el.classList.add('current'); }); diff --git a/src/Elastic.Markdown/Assets/styles.css b/src/Elastic.Markdown/Assets/styles.css index 472d55bd4..112eddee4 100644 --- a/src/Elastic.Markdown/Assets/styles.css +++ b/src/Elastic.Markdown/Assets/styles.css @@ -72,9 +72,8 @@ .sidebar { .sidebar-nav { - @apply sticky top-21 z-30 overflow-y-auto; + @apply sticky top-22 z-30 overflow-y-auto; max-height: calc(100vh - var(--spacing) * 22); - scrollbar-gutter: stable; } .sidebar-link { @@ -82,9 +81,7 @@ text-ink-light hover:text-black text-sm - text-wrap - inline-block - leading-[1.3em] + leading-[1.2em] tracking-[-0.02em]; } } @@ -172,7 +169,7 @@ } #pages-nav .current { - @apply font-semibold text-blue-elastic!; + @apply text-blue-elastic!; } .markdown-content { diff --git a/src/Elastic.Markdown/Helpers/Htmx.cs b/src/Elastic.Markdown/Helpers/Htmx.cs index 9e6422fb1..050af241e 100644 --- a/src/Elastic.Markdown/Helpers/Htmx.cs +++ b/src/Elastic.Markdown/Helpers/Htmx.cs @@ -2,50 +2,9 @@ // Elasticsearch B.V licenses this file to you under the Apache 2.0 License. // See the LICENSE file in the project root for more information -using System.Text; -using Elastic.Markdown.IO.Configuration; - namespace Elastic.Markdown.Helpers; -public static class Htmx +public class Htmx { - public static string GetHxSelectOob(FeatureFlags features, string? pathPrefix, string currentUrl, string targetUrl) - { - HashSet selectTargets = - [ - "#primary-nav", "#secondary-nav", "#markdown-content", "#toc-nav", "#prev-next-nav", "#breadcrumbs" - ]; - if (!HasSameTopLevelGroup(pathPrefix, currentUrl, targetUrl) && features.IsPrimaryNavEnabled) - _ = selectTargets.Add("#pages-nav"); - return string.Join(',', selectTargets); - } - - public static bool HasSameTopLevelGroup(string? pathPrefix, string currentUrl, string targetUrl) - { - var startIndex = pathPrefix?.Length ?? 0; - var currentSegments = GetSegments(currentUrl[startIndex..].Trim('/')); - var targetSegments = GetSegments(targetUrl[startIndex..].Trim('/')); - return currentSegments.Length >= 1 && targetSegments.Length >= 1 && currentSegments[0] == targetSegments[0]; - } - - public static string GetPreload() => "true"; - - public static string GetHxSwap() => "none"; - public static string GetHxPushUrl() => "true"; - public static string GetHxIndicator() => "#htmx-indicator"; - - private static string[] GetSegments(string url) => url.Split('/'); - - public static string GetHxAttributes(FeatureFlags features, string? pathPrefix, string currentUrl, string targetUrl) - { - - var attributes = new StringBuilder(); - _ = attributes.Append($" hx-get={targetUrl}"); - _ = attributes.Append($" hx-select-oob={GetHxSelectOob(features, pathPrefix, currentUrl, targetUrl)}"); - _ = attributes.Append($" hx-swap={GetHxSwap()}"); - _ = attributes.Append($" hx-push-url={GetHxPushUrl()}"); - _ = attributes.Append($" hx-indicator={GetHxIndicator()}"); - _ = attributes.Append($" preload={GetPreload()}"); - return attributes.ToString(); - } + public static string GetHxSelectOob() => "#markdown-content,#toc-nav,#prev-next-nav,#breadcrumbs"; } diff --git a/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs b/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs index 97e0afe36..081252678 100644 --- a/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs +++ b/src/Elastic.Markdown/IO/Configuration/ConfigurationFile.cs @@ -31,10 +31,6 @@ public record ConfigurationFile : DocumentationFile private readonly Dictionary _substitutions = new(StringComparer.OrdinalIgnoreCase); public IReadOnlyDictionary Substitutions => _substitutions; - private readonly Dictionary _features = new(StringComparer.OrdinalIgnoreCase); - private FeatureFlags? _featureFlags; - public FeatureFlags Features => _featureFlags ??= new FeatureFlags(_features); - public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildContext context, int depth = 0, string parentPath = "") : base(sourceFile, rootPath) { @@ -83,9 +79,6 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon TableOfContents = entries; break; - case "features": - _features = reader.ReadDictionary(entry.Entry).ToDictionary(k => k.Key, v => bool.Parse(v.Value), StringComparer.OrdinalIgnoreCase); - break; case "external_hosts": reader.EmitWarning($"{entry.Key} has been deprecated and will be removed", entry.Key); break; @@ -104,8 +97,6 @@ public ConfigurationFile(IFileInfo sourceFile, IDirectoryInfo rootPath, BuildCon Globs = [.. ImplicitFolders.Select(f => Glob.Parse($"{f}/*.md"))]; } - public bool IsFeatureEnabled(string feature) => _features.TryGetValue(feature, out var enabled) && enabled; - private List ReadChildren(YamlStreamReader reader, KeyValuePair entry, string parentPath) { var entries = new List(); diff --git a/src/Elastic.Markdown/IO/Configuration/FeatureFlags.cs b/src/Elastic.Markdown/IO/Configuration/FeatureFlags.cs deleted file mode 100644 index 57055de93..000000000 --- a/src/Elastic.Markdown/IO/Configuration/FeatureFlags.cs +++ /dev/null @@ -1,11 +0,0 @@ -// Licensed to Elasticsearch B.V under one or more agreements. -// Elasticsearch B.V licenses this file to you under the Apache 2.0 License. -// See the LICENSE file in the project root for more information - -namespace Elastic.Markdown.IO.Configuration; - -public class FeatureFlags(Dictionary featureFlags) -{ - public bool IsPrimaryNavEnabled => IsEnabled("primary-nav"); - private bool IsEnabled(string key) => featureFlags.TryGetValue(key, out var value) && value; -} diff --git a/src/Elastic.Markdown/IO/MarkdownFile.cs b/src/Elastic.Markdown/IO/MarkdownFile.cs index e99acc238..94c57e716 100644 --- a/src/Elastic.Markdown/IO/MarkdownFile.cs +++ b/src/Elastic.Markdown/IO/MarkdownFile.cs @@ -316,7 +316,7 @@ private YamlFrontMatter ReadYamlFrontMatter(string raw) } - public string CreateHtml(MarkdownDocument document) + public static string CreateHtml(MarkdownDocument document) { //we manually render title and optionally append an applies block embedded in yaml front matter. var h1 = document.Descendants().FirstOrDefault(h => h.Level == 1); @@ -324,13 +324,4 @@ public string CreateHtml(MarkdownDocument document) _ = document.Remove(h1); return document.ToHtml(MarkdownParser.Pipeline); } - - public static string CreateHtml(MarkdownDocument document, MarkdownParser parser) - { - //we manually render title and optionally append an applies block embedded in yaml front matter. - var h1 = document.Descendants().FirstOrDefault(h => h.Level == 1); - if (h1 is not null) - _ = document.Remove(h1); - return document.ToHtml(parser.Pipeline); - } } diff --git a/src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs b/src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs index 1453980d2..89b18c96a 100644 --- a/src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs +++ b/src/Elastic.Markdown/Myst/Directives/DirectiveHtmlRenderer.cs @@ -21,7 +21,7 @@ namespace Elastic.Markdown.Myst.Directives; /// An HTML renderer for a . /// /// -public class DirectiveHtmlRenderer(MarkdownParser markdownParser) : HtmlObjectRenderer +public class DirectiveHtmlRenderer : HtmlObjectRenderer { protected override void Write(HtmlRenderer renderer, DirectiveBlock directiveBlock) { @@ -62,10 +62,10 @@ protected override void Write(HtmlRenderer renderer, DirectiveBlock directiveBlo if (includeBlock.Literal) WriteLiteralIncludeBlock(renderer, includeBlock); else - WriteIncludeBlock(renderer, includeBlock, markdownParser); + WriteIncludeBlock(renderer, includeBlock); return; case SettingsBlock settingsBlock: - WriteSettingsBlock(renderer, settingsBlock, markdownParser); + WriteSettingsBlock(renderer, settingsBlock); return; default: // if (!string.IsNullOrEmpty(directiveBlock.Info) && !directiveBlock.Info.StartsWith('{')) @@ -219,24 +219,28 @@ private static void WriteLiteralIncludeBlock(HtmlRenderer renderer, IncludeBlock } } - private static void WriteIncludeBlock(HtmlRenderer renderer, IncludeBlock block, MarkdownParser parser) + private static void WriteIncludeBlock(HtmlRenderer renderer, IncludeBlock block) { if (!block.Found || block.IncludePath is null) return; + var parser = new MarkdownParser(block.Build, block.Context); var snippet = block.Build.ReadFileSystem.FileInfo.New(block.IncludePath); var parentPath = block.Context.MarkdownSourcePath; var document = parser.ParseSnippetAsync(snippet, parentPath, block.Context.YamlFrontMatter, default).GetAwaiter().GetResult(); - var html = document.ToHtml(parser.Pipeline); + var html = document.ToHtml(MarkdownParser.Pipeline); _ = renderer.Write(html); } - private static void WriteSettingsBlock(HtmlRenderer renderer, SettingsBlock block, MarkdownParser parser) + private static void WriteSettingsBlock(HtmlRenderer renderer, SettingsBlock block) { if (!block.Found || block.IncludePath is null) return; + var parser = new MarkdownParser(block.Build, block.Context); + var file = block.Build.ReadFileSystem.FileInfo.New(block.IncludePath); + YamlSettings? settings; try { @@ -260,7 +264,7 @@ private static void WriteSettingsBlock(HtmlRenderer renderer, SettingsBlock bloc RenderMarkdown = s => { var document = parser.ParseEmbeddedMarkdown(s, block.IncludeFrom, block.Context.YamlFrontMatter); - var html = document.ToHtml(parser.Pipeline); + var html = document.ToHtml(MarkdownParser.Pipeline); return html; } }); diff --git a/src/Elastic.Markdown/Myst/Directives/DirectiveMarkdownExtension.cs b/src/Elastic.Markdown/Myst/Directives/DirectiveMarkdownExtension.cs index c4246baa6..4f990e3b8 100644 --- a/src/Elastic.Markdown/Myst/Directives/DirectiveMarkdownExtension.cs +++ b/src/Elastic.Markdown/Myst/Directives/DirectiveMarkdownExtension.cs @@ -13,9 +13,9 @@ namespace Elastic.Markdown.Myst.Directives; public static class DirectiveMarkdownBuilderExtensions { - public static MarkdownPipelineBuilder UseDirectives(this MarkdownPipelineBuilder pipeline, MarkdownParser markdownParser) + public static MarkdownPipelineBuilder UseDirectives(this MarkdownPipelineBuilder pipeline) { - pipeline.Extensions.AddIfNotAlready(new DirectiveMarkdownExtension(markdownParser)); + pipeline.Extensions.AddIfNotAlready(); return pipeline; } } @@ -24,7 +24,7 @@ public static MarkdownPipelineBuilder UseDirectives(this MarkdownPipelineBuilder /// Extension to allow custom containers. /// /// -public class DirectiveMarkdownExtension(MarkdownParser markdownParser) : IMarkdownExtension +public class DirectiveMarkdownExtension : IMarkdownExtension { public void Setup(MarkdownPipelineBuilder pipeline) { @@ -53,7 +53,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) if (!renderer.ObjectRenderers.Contains()) { // Must be inserted before CodeBlockRenderer - _ = renderer.ObjectRenderers.InsertBefore(new DirectiveHtmlRenderer(markdownParser)); + _ = renderer.ObjectRenderers.InsertBefore(new DirectiveHtmlRenderer()); } _ = renderer.ObjectRenderers.Replace(new SectionedHeadingRenderer()); diff --git a/src/Elastic.Markdown/Myst/MarkdownParser.cs b/src/Elastic.Markdown/Myst/MarkdownParser.cs index befb60bba..67a7e9093 100644 --- a/src/Elastic.Markdown/Myst/MarkdownParser.cs +++ b/src/Elastic.Markdown/Myst/MarkdownParser.cs @@ -4,7 +4,6 @@ using System.IO.Abstractions; using Cysharp.IO; -using Elastic.Markdown.IO.Configuration; using Elastic.Markdown.Myst.CodeBlocks; using Elastic.Markdown.Myst.Comments; using Elastic.Markdown.Myst.Directives; @@ -102,33 +101,33 @@ private static async Task ParseAsync( } // ReSharper disable once InconsistentNaming - private MarkdownPipeline? _minimalPipelineCached; - private MarkdownPipeline MinimalPipeline + private static MarkdownPipeline? MinimalPipelineCached; + private static MarkdownPipeline MinimalPipeline { get { - if (_minimalPipelineCached is not null) - return _minimalPipelineCached; + if (MinimalPipelineCached is not null) + return MinimalPipelineCached; var builder = new MarkdownPipelineBuilder() .UseYamlFrontMatter() .UseInlineAnchors() .UseHeadingsWithSlugs() - .UseDirectives(this); + .UseDirectives(); _ = builder.BlockParsers.TryRemove(); - _minimalPipelineCached = builder.Build(); - return _minimalPipelineCached; + MinimalPipelineCached = builder.Build(); + return MinimalPipelineCached; } } // ReSharper disable once InconsistentNaming - private MarkdownPipeline? _pipelineCached; - public MarkdownPipeline Pipeline + private static MarkdownPipeline? PipelineCached; + public static MarkdownPipeline Pipeline { get { - if (_pipelineCached is not null) - return _pipelineCached; + if (PipelineCached is not null) + return PipelineCached; var builder = new MarkdownPipelineBuilder() .UseInlineAnchors() @@ -142,15 +141,15 @@ public MarkdownPipeline Pipeline .UseYamlFrontMatter() .UseGridTables() .UsePipeTables() - .UseDirectives(this) + .UseDirectives() .UseDefinitionLists() .UseEnhancedCodeBlocks() - .UseHtmxLinkInlineRenderer(Build) + .UseHtmxLinkInlineRenderer() .DisableHtml() .UseHardBreaks(); _ = builder.BlockParsers.TryRemove(); - _pipelineCached = builder.Build(); - return _pipelineCached; + PipelineCached = builder.Build(); + return PipelineCached; } } diff --git a/src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs b/src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs index 8fae9da96..094bd432b 100644 --- a/src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs +++ b/src/Elastic.Markdown/Myst/Renderers/HtmxLinkInlineRenderer.cs @@ -3,7 +3,6 @@ // See the LICENSE file in the project root for more information using Elastic.Markdown.Helpers; -using Elastic.Markdown.IO.Configuration; using Markdig; using Markdig.Renderers; using Markdig.Renderers.Html.Inlines; @@ -11,7 +10,7 @@ namespace Elastic.Markdown.Myst.Renderers; -public class HtmxLinkInlineRenderer(BuildContext build) : LinkInlineRenderer +public class HtmxLinkInlineRenderer : LinkInlineRenderer { protected override void Write(HtmlRenderer renderer, LinkInline link) { @@ -31,11 +30,11 @@ protected override void Write(HtmlRenderer renderer, LinkInline link) _ = renderer.Write(" hx-get=\""); _ = renderer.WriteEscapeUrl(link.GetDynamicUrl != null ? link.GetDynamicUrl() ?? link.Url : link.Url); _ = renderer.Write('"'); - _ = renderer.Write($" hx-select-oob=\"{Htmx.GetHxSelectOob(build.Configuration.Features, build.UrlPathPrefix, currentUrl, link.Url)}\""); + _ = renderer.Write($" hx-select-oob=\"{Htmx.GetHxSelectOob()}\""); _ = renderer.Write(" hx-swap=\"none\""); _ = renderer.Write(" hx-push-url=\"true\""); _ = renderer.Write(" hx-indicator=\"#htmx-indicator\""); - _ = renderer.Write($" preload=\"{Htmx.GetPreload()}\""); + _ = renderer.Write(" preload=\"mouseover\""); if (!string.IsNullOrEmpty(link.Title)) { @@ -63,14 +62,14 @@ protected override void Write(HtmlRenderer renderer, LinkInline link) public static class CustomLinkInlineRendererExtensions { - public static MarkdownPipelineBuilder UseHtmxLinkInlineRenderer(this MarkdownPipelineBuilder pipeline, BuildContext build) + public static MarkdownPipelineBuilder UseHtmxLinkInlineRenderer(this MarkdownPipelineBuilder pipeline) { - pipeline.Extensions.AddIfNotAlready(new HtmxLinkInlineRendererExtension(build)); + pipeline.Extensions.AddIfNotAlready(); return pipeline; } } -public class HtmxLinkInlineRendererExtension(BuildContext build) : IMarkdownExtension +public class HtmxLinkInlineRendererExtension : IMarkdownExtension { public void Setup(MarkdownPipelineBuilder pipeline) { @@ -82,7 +81,7 @@ public void Setup(MarkdownPipeline pipeline, IMarkdownRenderer renderer) if (renderer is HtmlRenderer htmlRenderer) { _ = htmlRenderer.ObjectRenderers.RemoveAll(x => x is LinkInlineRenderer); - htmlRenderer.ObjectRenderers.Add(new HtmxLinkInlineRenderer(build)); + htmlRenderer.ObjectRenderers.Add(new HtmxLinkInlineRenderer()); } } } diff --git a/src/Elastic.Markdown/Slices/HtmlWriter.cs b/src/Elastic.Markdown/Slices/HtmlWriter.cs index 55f16caf5..c4e5a1d1e 100644 --- a/src/Elastic.Markdown/Slices/HtmlWriter.cs +++ b/src/Elastic.Markdown/Slices/HtmlWriter.cs @@ -3,8 +3,6 @@ // See the LICENSE file in the project root for more information using System.IO.Abstractions; using Elastic.Markdown.IO; -using Elastic.Markdown.IO.Configuration; -using Elastic.Markdown.IO.Navigation; using Markdig.Syntax; using RazorSlices; @@ -14,25 +12,17 @@ public class HtmlWriter(DocumentationSet documentationSet, IFileSystem writeFile { private DocumentationSet DocumentationSet { get; } = documentationSet; - private async Task RenderNavigation(ConfigurationFile configuration, string topLevelGroupId, MarkdownFile markdown, Cancel ctx = default) + private async Task RenderNavigation(MarkdownFile markdown, Cancel ctx = default) { - var group = DocumentationSet.Tree.NavigationItems - .OfType() - .FirstOrDefault(i => i.Group.Id == topLevelGroupId)?.Group; - var slice = Layout._TocTree.Create(new NavigationViewModel { - Title = group?.Index?.NavigationTitle ?? DocumentationSet.Tree.Index!.NavigationTitle!, - TitleUrl = group?.Index?.Url ?? DocumentationSet.Tree.Index!.Url, - Tree = group ?? DocumentationSet.Tree, - CurrentDocument = markdown, - IsRoot = topLevelGroupId == DocumentationSet.Tree.Id, - Features = configuration.Features + Tree = DocumentationSet.Tree, + CurrentDocument = markdown }); return await slice.RenderAsync(cancellationToken: ctx); } - private readonly Dictionary _renderedNavigationCache = []; + private string? _renderedNavigation; public async Task RenderLayout(MarkdownFile markdown, Cancel ctx = default) { @@ -40,41 +30,11 @@ public async Task RenderLayout(MarkdownFile markdown, Cancel ctx = defau return await RenderLayout(markdown, document, ctx); } - private static string GetTopLevelGroupId(MarkdownFile markdown) => - markdown.YieldParentGroups().Length > 1 - ? markdown.YieldParentGroups()[^2] - : markdown.YieldParentGroups()[0]; - public async Task RenderLayout(MarkdownFile markdown, MarkdownDocument document, Cancel ctx = default) { - var html = markdown.CreateHtml(document); + var html = MarkdownFile.CreateHtml(document); await DocumentationSet.Tree.Resolve(ctx); - - var topLevelNavigationItems = DocumentationSet.Tree.NavigationItems - .OfType() - .Select(i => i.Group); - - string? navigationHtml; - - if (DocumentationSet.Configuration.Features.IsPrimaryNavEnabled) - { - var topLevelGroupId = GetTopLevelGroupId(markdown); - if (!_renderedNavigationCache.TryGetValue(topLevelGroupId, out var value)) - { - value = await RenderNavigation(DocumentationSet.Configuration, topLevelGroupId, markdown, ctx); - _renderedNavigationCache[topLevelGroupId] = value; - } - navigationHtml = value; - } - else - { - if (!_renderedNavigationCache.TryGetValue("root", out var value)) - { - value = await RenderNavigation(DocumentationSet.Configuration, DocumentationSet.Tree.Id, markdown, ctx); - _renderedNavigationCache["root"] = value; - } - navigationHtml = value; - } + _renderedNavigation ??= await RenderNavigation(markdown, ctx); var previous = DocumentationSet.GetPrevious(markdown); var next = DocumentationSet.GetNext(markdown); @@ -84,7 +44,6 @@ public async Task RenderLayout(MarkdownFile markdown, MarkdownDocument d var path = Path.Combine(DocumentationSet.RelativeSourcePath, markdown.RelativePath); var editUrl = $"https://github.com/elastic/{remote}/edit/{branch}/{path}"; - var slice = Index.Create(new IndexViewModel { Title = markdown.Title ?? "[TITLE NOT SET]", @@ -95,13 +54,11 @@ public async Task RenderLayout(MarkdownFile markdown, MarkdownDocument d CurrentDocument = markdown, PreviousDocument = previous, NextDocument = next, - TopLevelNavigationItems = [.. topLevelNavigationItems], - NavigationHtml = navigationHtml, + NavigationHtml = _renderedNavigation, UrlPathPrefix = markdown.UrlPathPrefix, Applies = markdown.YamlFrontMatter?.AppliesTo, GithubEditUrl = editUrl, - AllowIndexing = DocumentationSet.Build.AllowIndexing && !markdown.Hidden, - Features = DocumentationSet.Configuration.Features + AllowIndexing = DocumentationSet.Build.AllowIndexing && !markdown.Hidden }); return await slice.RenderAsync(cancellationToken: ctx); } diff --git a/src/Elastic.Markdown/Slices/Index.cshtml b/src/Elastic.Markdown/Slices/Index.cshtml index ec51e5529..85dfdb3e9 100644 --- a/src/Elastic.Markdown/Slices/Index.cshtml +++ b/src/Elastic.Markdown/Slices/Index.cshtml @@ -11,11 +11,9 @@ Previous = Model.PreviousDocument, Next = Model.NextDocument, NavigationHtml = Model.NavigationHtml, - TopLevelNavigationItems = Model.TopLevelNavigationItems, UrlPathPrefix = Model.UrlPathPrefix, GithubEditUrl = Model.GithubEditUrl, AllowIndexing = Model.AllowIndexing, - Features = Model.Features }; }
diff --git a/src/Elastic.Markdown/Slices/Layout/_Breadcrumbs.cshtml b/src/Elastic.Markdown/Slices/Layout/_Breadcrumbs.cshtml index cc71473ce..43999e8d6 100644 --- a/src/Elastic.Markdown/Slices/Layout/_Breadcrumbs.cshtml +++ b/src/Elastic.Markdown/Slices/Layout/_Breadcrumbs.cshtml @@ -4,13 +4,13 @@
  • Elastic @@ -24,11 +24,11 @@ itemprop="item" href="@item.Url" hx-get="@item.Url" - hx-select-oob="@Htmx.GetHxSelectOob(Model.Features, Model.UrlPathPrefix, item.Url, Model.CurrentDocument.Url)" + hx-select-oob="@Htmx.GetHxSelectOob()" hx-swap="none" hx-push-url="true" hx-indicator="#htmx-indicator" - preload="@Htmx.GetPreload()" + preload="mouseover" > @item.NavigationTitle diff --git a/src/Elastic.Markdown/Slices/Layout/_Header.cshtml b/src/Elastic.Markdown/Slices/Layout/_Header.cshtml index 408653e35..08c58a81a 100644 --- a/src/Elastic.Markdown/Slices/Layout/_Header.cshtml +++ b/src/Elastic.Markdown/Slices/Layout/_Header.cshtml @@ -1,196 +1,27 @@ -@using Elastic.Markdown.Helpers @inherits RazorSlice - -@{ - string GetHxAttributes(string url) - { - return Htmx.GetHxAttributes(Model.Features, Model.UrlPathPrefix, Model.CurrentDocument.Url, url); - } - - var primaryNavViewModel = new PrimaryNavViewModel - { - Items = - [ - new PrimaryNavItemViewModel - { - Title = "Get Started", - HtmxAttributes = GetHxAttributes(Model.Link("/get-started")), - Url = Model.Link("/get-started"), - }, - new PrimaryNavItemViewModel - { - Title = "Solutions and use cases", - Url = Model.Link("/solutions"), - HtmxAttributes = GetHxAttributes(Model.Link("/solutions")), - DropdownItems = [ - new PrimaryNavDropdownItemViewModel - { - IconPath = Model.Static("observability-logo-color-64px.svg"), - IconAlt = "Observability logo", - Title = "Observability", - Description = "Unify app and infrastructure visibility to proactively resolve issues.", - Url = Model.Link("/solutions/observability"), - HtmxAttributes = Htmx.GetHxAttributes( - Model.Features, - Model.CurrentDocument.UrlPathPrefix, - Model.CurrentDocument.Url, - Model.Link("/solutions/security") - ) - }, - new PrimaryNavDropdownItemViewModel - { - IconPath = Model.Static("security-logo-color-64px.svg"), - IconAlt = "Security logo", - Title = "Security", - Description = "Protect, investigate, and respond to cyber threats with AI-driven security analytics.", - Url = Model.Link("/solutions/security"), - HtmxAttributes = GetHxAttributes(Model.Link("/solutions/security")) - }, - new PrimaryNavDropdownItemViewModel - { - IconPath = Model.Static("elasticsearch-logo-color-64px.svg"), - IconAlt = "Search logo", - Title = "Search", - Description = "Discover a world of AI possibilities — built with the power of search.", - Url = Model.Link("/solutions/search"), - HtmxAttributes = GetHxAttributes(Model.Link("/solutions/search")) - } - ] - }, - new PrimaryNavItemViewModel - { - Title = "Work with the stack", - DropdownItems = [ - new PrimaryNavDropdownItemViewModel - { - Title = "Manage data", - Description = "Discover a world of AI possibilities — built with the power of search.", - Url = Model.Link("/manage-data"), - HtmxAttributes = GetHxAttributes(Model.Link("/manage-data")) - }, - new PrimaryNavDropdownItemViewModel - { - Title = "Explore and analyze", - Description = "Unify app and infrastructure visibility to proactively resolve issues.", - Url = Model.Link("/explore-analyze"), - HtmxAttributes = GetHxAttributes(Model.Link("/explore-analyze")) - }, - new PrimaryNavDropdownItemViewModel - { - Title = "Deploy and manage", - Description = "Unify app and infrastructure visibility to proactively resolve issues.", - Url = Model.Link("/deploy-manage"), - HtmxAttributes = GetHxAttributes(Model.Link("/deploy-manage")) - - }, - new PrimaryNavDropdownItemViewModel - { - Title = "Manage your cloud", - Description = "Unify app and infrastructure visibility to proactively resolve issues.", - Url = Model.Link("/cloud-account"), - HtmxAttributes = GetHxAttributes(Model.Link("/cloud-account")) - }, - ] - }, - new PrimaryNavItemViewModel - { - Title = "Troubleshoot", - HtmxAttributes = GetHxAttributes(Model.Link("/troubleshoot")), - Url = Model.Link("/troubleshoot"), - }, - ] - }; -} - -
    - -
    -
    -
    -
    -
    - - Elastic - -
    - @if (Model.Features.IsPrimaryNavEnabled) - { - @await RenderPartialAsync(_PrimaryNav.Create(primaryNavViewModel)) - } - else - { -
    - } -
  • "; var start = html.IndexOf(find, StringComparison.Ordinal); Html = start >= 0 diff --git a/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs index 309545177..526cd281b 100644 --- a/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/AnchorLinkTests.cs @@ -75,7 +75,7 @@ [Sub Requirements](testing/req.md#sub-requirements) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    Sub Requirements

    """ + """

    Sub Requirements

    """ ); [Fact] @@ -93,7 +93,7 @@ [Sub Requirements](testing/req.md#new-reqs) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    Sub Requirements

    """ + """

    Sub Requirements

    """ ); [Fact] @@ -110,7 +110,7 @@ public class ExternalPageAnchorAutoTitleTests(ITestOutputHelper output) : Anchor public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    Special Requirements > Sub Requirements

    """ + """

    Special Requirements > Sub Requirements

    """ ); [Fact] @@ -146,7 +146,7 @@ [Sub Requirements](testing/req.md#sub-requirements2) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    Sub Requirements

    """ + """

    Sub Requirements

    """ ); [Fact] @@ -165,7 +165,7 @@ [Heading inside dropdown](testing/req.md#heading-inside-dropdown) public void GeneratesHtml() => // language=html Html.Should().Contain( - """Heading inside dropdown""" + """Heading inside dropdown""" ); [Fact] public void HasError() => Collector.Diagnostics.Should().HaveCount(0); diff --git a/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs index 6d570c2c0..d5549f6c2 100644 --- a/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/DirectiveBlockLinkTests.cs @@ -66,7 +66,7 @@ [Sub Requirements](testing/req.md#hint_ref) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    Sub Requirements

    """ + """

    Sub Requirements

    """ ); [Fact] diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs index f5c95cae2..df6669b9b 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineAnchorTests.cs @@ -200,7 +200,7 @@ [Sub Requirements](testing/req.md#custom-anchor) public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    Sub Requirements

    """ + """

    Sub Requirements

    """ ); [Fact] diff --git a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs index 999ac3656..c7d08cb01 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlineLinkTests.cs @@ -41,7 +41,7 @@ public class InlineLinkTests(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    Elasticsearch

    """ + """

    Elasticsearch

    """ ); [Fact] @@ -58,7 +58,7 @@ public class LinkToPageTests(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    Requirements

    """ + """

    Requirements

    """ ); [Fact] @@ -78,7 +78,7 @@ public class InsertPageTitleTests(ITestOutputHelper output) : LinkTestBase(outpu public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    Special Requirements

    """ + """

    Special Requirements

    """ ); [Fact] @@ -100,7 +100,7 @@ public class LinkReferenceTest(ITestOutputHelper output) : LinkTestBase(output, public void GeneratesHtml() => // language=html Html.Should().Contain( - """

    test

    """ + """

    test

    """ ); [Fact] @@ -231,10 +231,10 @@ public void GeneratesHtml() => Html.TrimEnd().Should().Be("""

    Links:

    """); diff --git a/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs b/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs index 700c51004..2ef781cd7 100644 --- a/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs +++ b/tests/Elastic.Markdown.Tests/Inline/InlneBaseTests.cs @@ -129,7 +129,7 @@ public virtual async ValueTask InitializeAsync() await Set.LinkResolver.FetchLinks(); Document = await File.ParseFullAsync(default); - var html = File.CreateHtml(Document).AsSpan(); + var html = MarkdownFile.CreateHtml(Document).AsSpan(); var find = "\n"; var start = html.IndexOf(find, StringComparison.Ordinal); Html = start >= 0 && !TestingFullDocument