From dc773219c134a99b510fdc323c700980704c3be9 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Tue, 10 Sep 2024 08:49:40 +0200 Subject: [PATCH] feat(redirect): remove support for permanent redirects can be introduced later if needed, but omitted now because they are hard to undo later --- src/middleware.ts | 5 ++--- studio/components/RedirectThumbnail.tsx | 5 ----- studio/lib/payloads/redirect.ts | 1 - studio/schemas/documents/redirect.ts | 24 +----------------------- 4 files changed, 3 insertions(+), 32 deletions(-) delete mode 100644 studio/components/RedirectThumbnail.tsx diff --git a/src/middleware.ts b/src/middleware.ts index 94e6af24a..dd4e5e816 100644 --- a/src/middleware.ts +++ b/src/middleware.ts @@ -6,14 +6,13 @@ export async function middleware(request: NextRequest) { const slug = request.nextUrl.pathname; const redirect = await client.fetch( `*[_type == "redirect" && source.current == "${slug}"][0]{ - "destination":destination.current, - permanent + "destination":destination.current }`, ); if (redirect !== null) { return NextResponse.redirect( new URL(redirect.destination, request.url), - redirect.permanent ? 308 : 307, + 307, ); } } diff --git a/studio/components/RedirectThumbnail.tsx b/studio/components/RedirectThumbnail.tsx deleted file mode 100644 index 04c1fd0ce..000000000 --- a/studio/components/RedirectThumbnail.tsx +++ /dev/null @@ -1,5 +0,0 @@ -const RedirectThumbnail = ({ permanent }: { permanent: boolean }) => { - return {permanent ? "⮕" : "⇢"}; -}; - -export default RedirectThumbnail; diff --git a/studio/lib/payloads/redirect.ts b/studio/lib/payloads/redirect.ts index f3b11e53a..1d904f0df 100644 --- a/studio/lib/payloads/redirect.ts +++ b/studio/lib/payloads/redirect.ts @@ -4,5 +4,4 @@ export interface RedirectPage extends RedirectSparsePage { export interface RedirectSparsePage { destination: string; - permanent: boolean; } diff --git a/studio/schemas/documents/redirect.ts b/studio/schemas/documents/redirect.ts index 899e99de5..1f490aaf7 100644 --- a/studio/schemas/documents/redirect.ts +++ b/studio/schemas/documents/redirect.ts @@ -1,6 +1,5 @@ import { defineField, defineType, type Slug } from "sanity"; import { SlugRule } from "@sanity/types"; -import RedirectThumbnail from "../../components/RedirectThumbnail"; import { pageBuilderID } from "../builders/pageBuilder"; import { blogId } from "./blog"; import { compensationsId } from "./compensations"; @@ -18,16 +17,6 @@ const redirect = defineType({ name: redirectId, title: "Redirect", type: "document", - readOnly: (ctx) => { - /* - make permanent redirects read-only after initial publish - this is a soft guardrail that is possible to bypass - */ - return ( - (ctx.document?.permanent ?? false) && - !ctx.document?._id.startsWith("drafts.") - ); - }, fields: [ defineField({ name: "source", @@ -92,14 +81,6 @@ const redirect = defineType({ }), ], }), - defineField({ - name: "permanent", - title: "Permanent", - description: - "Will this redirect exist throughout the foreseeable future?", - type: "boolean", - initialValue: false, - }), ], preview: { select: { @@ -107,14 +88,12 @@ const redirect = defineType({ destinationType: "destination.type", destinationSlug: "destination.slug.current", destinationReferenceSlug: "destination.reference.slug.current", - permanent: "permanent", }, prepare({ source, destinationType, destinationSlug, destinationReferenceSlug, - permanent, }) { const destination = destinationType === "slug" ? destinationSlug : destinationReferenceSlug; @@ -124,8 +103,7 @@ const redirect = defineType({ : undefined; return { title, - subtitle: permanent ? "Permanent" : "Temporary", - media: RedirectThumbnail({ permanent }), + subtitle: "type: " + destinationType, }; }, },