Skip to content

Commit db2beec

Browse files
committed
feat: improve URL generation with added variations and simplified path handling
- Added trailing-slash variations for directory-style URLs in `OutputGenerationService`. - Simplified relative path generation in `RecipeContentService` to improve output file path handling.
1 parent a78eec1 commit db2beec

2 files changed

Lines changed: 8 additions & 4 deletions

File tree

examples/RecipeExample/RecipeContentService.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -141,10 +141,8 @@ async Task<ImmutableList<PageToGenerate>> IContentService.GetPagesToGenerateAsyn
141141
// Add individual recipe pages
142142
foreach (var (url, recipePage) in data)
143143
{
144-
145-
var relativePath = url.Replace('/', Path.DirectorySeparatorChar);
146-
147-
var outputFile = _fileSystem.Path.Combine(_options.BasePageUrl, relativePath.Trim(Path.DirectorySeparatorChar), "index.html").TrimStart(Path.DirectorySeparatorChar);
144+
var relativePath = url.TrimStart('/').Replace('/', Path.DirectorySeparatorChar);
145+
var outputFile = _fileSystem.Path.Combine(relativePath, "index.html");
148146

149147
pages.Add(new PageToGenerate(url, outputFile, new Metadata()
150148
{

src/MyLittleContentEngine/Services/Generation/OutputGenerationService.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -557,6 +557,12 @@ private ImmutableHashSet<string> BuildValidOutputPathsLookup(
557557
validPaths.Add(normalizedUrl + ".html");
558558
}
559559

560+
// Add trailing-slash variation for directory-style URLs
561+
if (!normalizedUrl.EndsWith('/') && !Path.HasExtension(normalizedUrl))
562+
{
563+
validPaths.Add(normalizedUrl + "/");
564+
}
565+
560566
// Add version without .html extension for pages that have it
561567
// This allows both /about.html and /about to be valid
562568
if (normalizedUrl.EndsWith(".html", StringComparison.OrdinalIgnoreCase))

0 commit comments

Comments
 (0)