Skip to content

Commit 68a41f8

Browse files
authored
fix 183 prevent index pages from being listed twice (#189)
1 parent fa42893 commit 68a41f8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/Elastic.Markdown/IO/Navigation/DocumentationGroup.cs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,12 +41,11 @@ public DocumentationGroup(
4141
)
4242
{
4343
Depth = depth;
44-
var foundIndex = ProcessTocItems(toc, lookup, folderLookup, depth, out var groups, out var files, out var navigationItems);
44+
Index = ProcessTocItems(index, toc, lookup, folderLookup, depth, out var groups, out var files, out var navigationItems);
4545

4646
GroupsInOrder = groups;
4747
FilesInOrder = files;
4848
NavigationItems = navigationItems;
49-
Index = index ?? foundIndex;
5049

5150
if (Index is not null)
5251
FilesInOrder = FilesInOrder.Except([Index]).ToList();
@@ -55,19 +54,19 @@ public DocumentationGroup(
5554
}
5655

5756
private MarkdownFile? ProcessTocItems(
57+
MarkdownFile? configuredIndex,
5858
IReadOnlyCollection<ITocItem> toc,
5959
IDictionary<string, DocumentationFile> lookup,
6060
IDictionary<string, DocumentationFile[]> folderLookup,
6161
int depth,
6262
out List<DocumentationGroup> groups,
6363
out List<MarkdownFile> files,
64-
out List<INavigationItem> navigationItems
65-
)
64+
out List<INavigationItem> navigationItems)
6665
{
6766
groups = [];
6867
navigationItems = [];
6968
files = [];
70-
MarkdownFile? indexFile = null;
69+
var indexFile = configuredIndex;
7170
foreach (var (tocItem, index) in toc.Select((t, i) => (t, i)))
7271
{
7372
if (tocItem is FileReference file)
@@ -89,9 +88,14 @@ out List<INavigationItem> navigationItems
8988
}
9089

9190
files.Add(md);
92-
navigationItems.Add(new FileNavigation(index, depth, md));
9391
if (file.Path.EndsWith("index.md") && d is MarkdownFile i)
9492
indexFile ??= i;
93+
94+
// add the page to navigation items unless it's the index file
95+
// the index file can either be the discovered `index.md` or the parent group's
96+
// explicit index page. E.g. when grouping related files together.
97+
if (indexFile != md)
98+
navigationItems.Add(new FileNavigation(index, depth, md));
9599
}
96100
else if (tocItem is FolderReference folder)
97101
{

0 commit comments

Comments
 (0)