add redirect for individual slugs
This commit is contained in:
parent
3242c3bc77
commit
4edacb1213
|
@ -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);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue