Skip to content

Commit a78eec1

Browse files
committed
fix: handle "index" files in root directory correctly in URL path generation
- Updated `FileSystemUtilities.FilePathToUrlPath` to return an empty URL path for `index` files in the root directory. - Adjusted related test case to validate the new behavior.
1 parent 17c59e0 commit a78eec1

2 files changed

Lines changed: 8 additions & 2 deletions

File tree

src/MyLittleContentEngine/Services/Infrastructure/FileSystemUtilities.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,12 @@ public UrlPath FilePathToUrlPath(FilePath filePath, FilePath baseContentPath)
2323
var directoryPath = _filePathOps.GetDirectory(relativePath);
2424
var fileNameWithoutExtension = _filePathOps.GetFileNameWithoutExtension(relativePath).Slugify();
2525

26+
// index.md represents the directory itself, not a page called "index"
27+
if (fileNameWithoutExtension.Equals("index", StringComparison.OrdinalIgnoreCase))
28+
{
29+
return directoryPath.IsEmpty ? UrlPath.Empty : directoryPath.ToUrlPath();
30+
}
31+
2632
var result = _filePathOps.Combine(directoryPath, fileNameWithoutExtension);
2733
return result.ToUrlPath();
2834
}

tests/MyLittleContentEngine.Tests/Infrastructure/FileSystemUtilitiesTests.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ public void ValidateDirectoryPath_NonExistingDirectory_ThrowsDirectoryNotFoundEx
147147
}
148148

149149
[Fact]
150-
public void FilePathToUrlPath_FileInRootDirectory_ReturnsJustFilename()
150+
public void FilePathToUrlPath_IndexFileInRootDirectory_ReturnsEmpty()
151151
{
152152
var fileSystem = new MockFileSystem();
153153
var pathUtilities = CreateFileSystemUtilities(fileSystem);
@@ -156,7 +156,7 @@ public void FilePathToUrlPath_FileInRootDirectory_ReturnsJustFilename()
156156

157157
var result = pathUtilities.FilePathToUrlPath(filePath, baseContentPath);
158158

159-
result.Value.ShouldBe("index");
159+
result.IsEmpty.ShouldBeTrue();
160160
}
161161

162162
[Fact]

0 commit comments

Comments
 (0)