Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 24 additions & 0 deletions src/Elastic.Markdown/IO/DocumentationSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public DocumentationSet(

Tree = new TableOfContentsTree(Source, Context, lookups, treeCollector, ref fileIndex);

var navigationIndex = 0;
UpdateNavigationIndex(Tree.NavigationItems, ref navigationIndex);
var markdownFiles = Files.OfType<MarkdownFile>().ToArray();

var excludedChildren = markdownFiles.Where(f => !f.PartOfNavigation).ToArray();
Expand All @@ -210,6 +212,28 @@ public DocumentationSet(
ValidateRedirectsExists();
}

private void UpdateNavigationIndex(IReadOnlyCollection<INavigationItem> navigationItems, ref int navigationIndex)
{
foreach (var item in navigationItems)
{
switch (item)
{
case FileNavigationItem fileNavigationItem:
var fileIndex = Interlocked.Increment(ref navigationIndex);
fileNavigationItem.NavigationIndex = fileIndex;
break;
case DocumentationGroup documentationGroup:
var groupIndex = Interlocked.Increment(ref navigationIndex);
documentationGroup.NavigationIndex = groupIndex;
UpdateNavigationIndex(documentationGroup.NavigationItems, ref navigationIndex);
break;
default:
Context.EmitError(Context.ConfigurationPath, $"Unhandled navigation item type: {item.GetType()}");
break;
}
}
}

public FrozenDictionary<int, INavigationItem> NavigationIndexedByOrder { get; }

private static IReadOnlyCollection<INavigationItem> CreateNavigationLookup(INavigationItem item)
Expand Down
16 changes: 13 additions & 3 deletions src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,15 @@ out List<INavigationItem> navigationItems
groups = [];
navigationItems = [];
files = [];
var fileReferences = lookups.TableOfContents.OfType<FileReference>().ToArray();
var indexFile = virtualIndexFile;
FileReference? indexReference = null;
if (indexFile is null)
{
indexReference =
fileReferences.FirstOrDefault(f => f.RelativePath.EndsWith("index.md"))
?? fileReferences.FirstOrDefault();
}

var list = navigationItems;

Expand Down Expand Up @@ -158,14 +166,16 @@ void AddToNavigationItems(INavigationItem item, ref int fileIndex)
}

files.Add(md);
if (file.RelativePath.EndsWith("index.md") && d is MarkdownFile i)
indexFile ??= i;
if (file.RelativePath.EndsWith("index.md"))
indexFile ??= md;
else if (indexReference == file)
indexFile ??= md;

// Add the page to navigation items unless it's the index file
// the index file can either be the discovered `index.md` or the parent group's
// explicit index page. E.g., when grouping related files together.
// If the page is referenced as hidden in the TOC do not include it in the navigation
if (indexFile != md)
if (indexFile != md && indexReference != file)
AddToNavigationItems(new FileNavigationItem(md, this, file.Hidden), ref fileIndex);
}
else if (tocItem is FolderReference folder)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,8 @@ public async Task ParsesReferences()

var navigation = new GlobalNavigation(assembleSources, navigationFile);
var referenceNav = navigation.NavigationLookup[expectedRoot];
navigation.NavigationItems.Should().HaveSameCount(navigation.NavigationLookup);
navigation.NavigationItems.OfType<TableOfContentsTree>()
.Should().HaveSameCount(navigation.NavigationLookup);

referenceNav.Should().NotBeNull();
var navigationLookup = referenceNav.NavigationItems.OfType<TableOfContentsTree>().ToDictionary(i => i.Source, i => i);
Expand Down Expand Up @@ -314,11 +315,11 @@ public async Task UriResolving()
var resolvedUri = uriResolver.Resolve(new Uri("docs-content://reference/apm/something.md"), "/reference/apm/something");
resolvedUri.Should().Be("https://www.elastic.co/docs/reference/apm/something");

resolvedUri = uriResolver.Resolve(new Uri("apm-agent-ios://reference/instrumentation.md"), "/reference/instrumentation");
resolvedUri.Should().Be("https://www.elastic.co/docs/reference/apm/agents/ios/instrumentation");
resolvedUri = uriResolver.Resolve(new Uri("apm-agent-nodejs://reference/instrumentation.md"), "/reference/instrumentation");
resolvedUri.Should().Be("https://www.elastic.co/docs/reference/apm/agents/nodejs/instrumentation");

resolvedUri = uriResolver.Resolve(new Uri("apm-agent-android://reference/a/file.md"), "/reference/a/file");
resolvedUri.Should().Be("https://www.elastic.co/docs/reference/apm/agents/android/a/file");
resolvedUri = uriResolver.Resolve(new Uri("apm-agent-dotnet://reference/a/file.md"), "/reference/a/file");
resolvedUri.Should().Be("https://www.elastic.co/docs/reference/apm/agents/dotnet/a/file");

resolvedUri = uriResolver.Resolve(new Uri("elasticsearch-net://reference/b/file.md"), "/reference/b/file");
resolvedUri.Should().Be("https://www.elastic.co/docs/reference/elasticsearch/clients/dotnet/b/file");
Expand Down
Loading