|
126 | 126 | // Fallback for dynamic post routes without a static exported page. |
127 | 127 | // If a specific post HTML exists, serve it; otherwise serve the generic |
128 | 128 | // placeholder page that loads the post client-side from the API. |
129 | | -app.MapGet("/posts/{id:long}/{slug}", (long id, string slug, IWebHostEnvironment env) => |
| 129 | +var fallbackRoutes = new Dictionary<string, string> |
130 | 130 | { |
131 | | - var staticPostPath = Path.Combine(env.WebRootPath, "posts", id.ToString(), $"{slug}.html"); |
132 | | - if (File.Exists(staticPostPath)) |
133 | | - return Results.File(staticPostPath, "text/html; charset=utf-8"); |
134 | | - |
135 | | - var placeholderPath = Path.Combine(env.WebRootPath, "posts", "0", "_placeholder", "index.html"); |
136 | | - if (File.Exists(placeholderPath)) |
137 | | - return Results.File(placeholderPath, "text/html; charset=utf-8"); |
| 131 | + ["/posts/{id:long}/{slug}"] = "posts/0/_placeholder/index.html", |
| 132 | + ["/tech/{slug}"] = "tech/_placeholder.html", |
| 133 | + ["/stacks/{slug}"] = "stacks/_placeholder.html", |
| 134 | +}; |
| 135 | +foreach (var route in fallbackRoutes) |
| 136 | +{ |
| 137 | + app.MapGet(route.Key, (HttpContext ctx, IWebHostEnvironment env) => |
| 138 | + { |
| 139 | + var placeholderPath = Path.Combine(env.WebRootPath, route.Value); |
| 140 | + if (File.Exists(placeholderPath)) |
| 141 | + return Results.File(placeholderPath, "text/html; charset=utf-8"); |
138 | 142 |
|
139 | | - return Results.NotFound(); |
140 | | -}); |
| 143 | + return Results.NotFound(); |
| 144 | + }); |
| 145 | +} |
141 | 146 |
|
142 | 147 | // GitHub OAuth endpoint |
143 | 148 | app.MapGet("/auth/github", ( |
|
0 commit comments