Custom URL Redirects

This commit is contained in:
2025-06-09 22:11:54 +01:00
committed by GitHub
parent 7774d0e318
commit 0437e5b8bd
2 changed files with 34 additions and 0 deletions

View File

@@ -0,0 +1,22 @@
import { redirect } from '@sveltejs/kit';
import { getFromCMS } from 'utils/utils.js';
const redirectQuery = `*[_type == "redirects"]{ shortname, url }`;
export const load = async ({ params }) => {
/** @type {[{shortname: String, url: String}]} */
let CMSresponse = await getFromCMS(redirectQuery);
const { shortname } = params;
CMSresponse.forEach(res => {
if(res.shortname == shortname) {
// if match
throw redirect(302, res.url);
}
});
return {
shortname: shortname,
}
};

View File

@@ -0,0 +1,12 @@
<script>
import Section from 'components/Section.svelte';
let { data } = $props();
</script>
<Section>
<p class="page-title">Where am I?</p>
<p>
Oops! We don't have a page for <code>"r/{data.shortname}"</code>.
</p>
<p>Please try again!</p>
</Section>