Skip to content

Commit 1643d03

Browse files
authored
Redirect to first markdownfile on serve command in case index.md doesn't exist (#956)
1 parent c7a36d2 commit 1643d03

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

src/docs-builder/Http/DocumentationWebHost.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -178,12 +178,14 @@ private static async Task<IResult> ServeDocumentationFile(ReloadableGeneratorSta
178178
case ImageFile image:
179179
return Results.File(image.SourceFile.FullName, image.MimeType);
180180
default:
181-
if (generator.DocumentationSet.FlatMappedFiles.TryGetValue("404.md", out var notFoundDocumentationFile))
182-
{
183-
var renderedNotFound = await generator.RenderLayout((notFoundDocumentationFile as MarkdownFile)!, ctx);
184-
return Results.Content(renderedNotFound, "text/html", null, (int)HttpStatusCode.NotFound);
185-
}
186-
return Results.NotFound();
181+
if (s == "index.md")
182+
return Results.Redirect(generator.DocumentationSet.MarkdownFiles.First().Value.Url);
183+
184+
if (!generator.DocumentationSet.FlatMappedFiles.TryGetValue("404.md", out var notFoundDocumentationFile))
185+
return Results.NotFound();
186+
187+
var renderedNotFound = await generator.RenderLayout((notFoundDocumentationFile as MarkdownFile)!, ctx);
188+
return Results.Content(renderedNotFound, "text/html", null, (int)HttpStatusCode.NotFound);
187189
}
188190
}
189191
}

0 commit comments

Comments
 (0)