From 75d6a5712fe57f3bd56874c8b8f388f84926f176 Mon Sep 17 00:00:00 2001 From: Jan Calanog Date: Thu, 3 Apr 2025 09:30:29 +0200 Subject: [PATCH] Redirect to first markdownfile on serve command in case index.md doesn't exist --- src/docs-builder/Http/DocumentationWebHost.cs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/docs-builder/Http/DocumentationWebHost.cs b/src/docs-builder/Http/DocumentationWebHost.cs index 1d2fe4f03..ca55d1545 100644 --- a/src/docs-builder/Http/DocumentationWebHost.cs +++ b/src/docs-builder/Http/DocumentationWebHost.cs @@ -178,12 +178,14 @@ private static async Task ServeDocumentationFile(ReloadableGeneratorSta case ImageFile image: return Results.File(image.SourceFile.FullName, image.MimeType); default: - if (generator.DocumentationSet.FlatMappedFiles.TryGetValue("404.md", out var notFoundDocumentationFile)) - { - var renderedNotFound = await generator.RenderLayout((notFoundDocumentationFile as MarkdownFile)!, ctx); - return Results.Content(renderedNotFound, "text/html", null, (int)HttpStatusCode.NotFound); - } - return Results.NotFound(); + if (s == "index.md") + return Results.Redirect(generator.DocumentationSet.MarkdownFiles.First().Value.Url); + + if (!generator.DocumentationSet.FlatMappedFiles.TryGetValue("404.md", out var notFoundDocumentationFile)) + return Results.NotFound(); + + var renderedNotFound = await generator.RenderLayout((notFoundDocumentationFile as MarkdownFile)!, ctx); + return Results.Content(renderedNotFound, "text/html", null, (int)HttpStatusCode.NotFound); } } }