From 4edacb1213bc95eff7f7739cdc21f3096ef6bb7a Mon Sep 17 00:00:00 2001 From: Silas Date: Thu, 6 Jun 2024 23:51:08 -0400 Subject: [PATCH] add redirect for individual slugs --- src/hooks.server.ts | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) 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); +}