diff --git a/src/hooks.server.ts b/src/hooks.server.ts index c526875..fbd8f68 100644 --- a/src/hooks.server.ts +++ b/src/hooks.server.ts @@ -1,5 +1,6 @@ import { getModel } from '$lib/utils/search'; import { building } from '$app/environment'; +import { redirect } from '@sveltejs/kit'; if (!building) { getModel().catch((error) => { @@ -8,3 +9,25 @@ if (!building) { 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); +}