1
0
mirror of https://github.com/kamranahmedse/developer-roadmap.git synced 2025-04-15 12:53:41 +02:00

Add 404 handling

This commit is contained in:
Kamran Ahmed 2025-04-07 16:39:09 +01:00
parent a2e83e909e
commit 7f28a755dc
3 changed files with 8 additions and 5 deletions

1
.astro/types.d.ts vendored
View File

@ -1,2 +1 @@
/// <reference types="astro/client" />
/// <reference path="content.d.ts" />

View File

@ -3,8 +3,6 @@ import Icon from '../components/AstroIcon.astro';
import BaseLayout from '../layouts/BaseLayout.astro';
import { getRoadmapIds } from '../lib/roadmap';
export const prerender = true;
const roadmapIds = await getRoadmapIds();
const legacyRoadmapUrls = [...roadmapIds.map((id) => `/${id}/`), '/roadmaps/'];
---

View File

@ -10,7 +10,10 @@ export const prerender = false;
const { topicId, roadmapId } = Astro.params;
if (!topicId || !roadmapId) {
return Astro.redirect('/404');
Astro.response.status = 404;
Astro.response.statusText = 'Not found';
return Astro.rewrite('/404');
}
// Handle nested paths by joining the segments
@ -48,7 +51,10 @@ if (!fs.existsSync(contentPath)) {
);
if (!fs.existsSync(indexFilePath)) {
return Astro.redirect('/404');
Astro.response.status = 404;
Astro.response.statusText = 'Not found';
return Astro.rewrite('/404');
}
contentPath = indexFilePath;