add redirect for individual slugs

This commit is contained in:
Silas 2024-06-06 23:51:08 -04:00
parent 3242c3bc77
commit 4edacb1213
Failed to generate hash of commit
1 changed files with 23 additions and 0 deletions

View File

@ -1,5 +1,6 @@
import { getModel } from '$lib/utils/search'; import { getModel } from '$lib/utils/search';
import { building } from '$app/environment'; import { building } from '$app/environment';
import { redirect } from '@sveltejs/kit';
if (!building) { if (!building) {
getModel().catch((error) => { getModel().catch((error) => {
@ -8,3 +9,25 @@ if (!building) {
console.log('Model loaded successfully!'); console.log('Model loaded successfully!');
} }
const redirectMap = new Map([
['/writes/', '/poetry/'],
['/rants/', '/thoughts/'],
['/works/', '/projects/']
]);
// redirect old paths
export async function handle({ event, resolve }) {
const url = event.request.url;
const path = new URL(url).pathname;
for (const [oldPath, newPath] of redirectMap.entries()) {
if (path.startsWith(oldPath)) {
const redirectedPath = path.replace(oldPath, newPath);
throw redirect(301, redirectedPath);
}
}
// Continue with the normal flow if no redirect is needed
return resolve(event);
}