Files
sweet/www/routes/docs/_middleware.ts
T
Marvin Hagemeister 1daca75489 feat: bring back <Head> component (#3249)
This PR brings back the `<Head>` component from Fresh 1.x . The
implementation is much cleaner than back then and also works client-side
now too.
2025-08-25 15:40:47 +02:00

22 lines
592 B
TypeScript

import type { Context } from "fresh";
const REDIRECTS: Record<string, string> = {
"/docs/getting-started/fetching-data":
"/docs/getting-started/custom-handlers",
"/docs/canary/examples/modifying-the-head": "/docs/canary/advanced/head",
};
export async function handler<T>(ctx: Context<T>) {
// Redirect from old doc URLs to new ones
const redirect = REDIRECTS[ctx.url.pathname];
if (redirect) {
const url = new URL(redirect, ctx.url.origin);
return new Response("", {
status: 307,
headers: { location: url.href },
});
}
return await ctx.next();
}