From 455c463fd2e59d7ffd434cef3eb87705613b15d6 Mon Sep 17 00:00:00 2001
From: Martin Tirion <mtirion@microsoft.com>
Date: Tue, 20 Aug 2024 11:55:01 +0200
Subject: [PATCH] Fixed issue with ignoring generated index.md in folder with 1
 file

---
 .gitignore                            |  1 +
 src/DocFxTocGenerator/TocGenerator.cs | 11 ++++++++++-
 2 files changed, 11 insertions(+), 1 deletion(-)

diff --git a/.gitignore b/.gitignore
index e7bb183..14bd891 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,6 +6,7 @@
 # User-specific files
 *.zip
 [Oo]utput/
+launchSettings.json
 
 *.rsuser
 *.suo
diff --git a/src/DocFxTocGenerator/TocGenerator.cs b/src/DocFxTocGenerator/TocGenerator.cs
index 8151697..f319fd0 100644
--- a/src/DocFxTocGenerator/TocGenerator.cs
+++ b/src/DocFxTocGenerator/TocGenerator.cs
@@ -403,7 +403,16 @@ private static void GetDirectories(DirectoryInfo folder, List<string> order, Toc
 
                 if (subFiles.Length == 1 && dirInfo.GetDirectories().Length == 0)
                 {
-                    newTocItem.Href = GetRelativePath(subFiles[0].FullName, _options.DocFolder);
+                    if (!string.IsNullOrEmpty(entryFile))
+                    {
+                        // if we have added an index file, so we'll point to that one
+                        newTocItem.Href = GetRelativePath(entryFile, _options.DocFolder);
+                    }
+                    else
+                    {
+                        // otherwise: the first file.
+                        newTocItem.Href = GetRelativePath(subFiles[0].FullName, _options.DocFolder);
+                    }
                 }
                 else
                 {