diff --git a/src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs b/src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs index a0a98dd81..60b9f02c9 100644 --- a/src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs +++ b/src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs @@ -116,6 +116,8 @@ internal TableOfContentsTree( TreeCollector.Collect(source, this); } + protected override DocumentationGroup DefaultNavigation => this; + } [DebuggerDisplay("Group >{Depth} {FolderName} ({NavigationItems.Count} items)")] @@ -147,6 +149,8 @@ public class DocumentationGroup : INavigationGroup public string FolderName { get; } + protected virtual DocumentationGroup DefaultNavigation => this; + protected DocumentationGroup( TableOfContentsTreeCollector treeCollector, BuildContext context, @@ -178,7 +182,13 @@ protected DocumentationGroup( NavigationSource = navigationSource; _treeCollector = treeCollector; Depth = depth; - toplevelTree ??= this; + // Virtual calls don't use state so while ugly not an issue + // We'll need to address this more structurally + // ReSharper disable VirtualMemberCallInConstructor + toplevelTree ??= DefaultNavigation; + if (parent?.Depth == 0) + toplevelTree = DefaultNavigation; + // ReSharper enable VirtualMemberCallInConstructor NavigationRoot = toplevelTree; // ReSharper restore VirtualMemberCallInConstructor Index = ProcessTocItems(context, toplevelTree, index, lookups, depth, ref fileIndex, out var groups, out var files, out var navigationItems);