From b791c4537b2f773ba0c1311841b616be5292ca3c Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Mon, 14 Oct 2024 11:13:35 +0200 Subject: [PATCH] feat: remove redirects/broken links schema --- studio/deskStructure.ts | 6 - studio/schema.ts | 2 - .../documents/siteSettings/brokenLink.ts | 135 ------------------ studio/schemas/schemaTypes/slug.ts | 3 +- 4 files changed, 1 insertion(+), 145 deletions(-) delete mode 100644 studio/schemas/documents/siteSettings/brokenLink.ts diff --git a/studio/deskStructure.ts b/studio/deskStructure.ts index ac19c749e..16e40a722 100644 --- a/studio/deskStructure.ts +++ b/studio/deskStructure.ts @@ -1,7 +1,6 @@ import { CaseIcon, CogIcon, - DoubleChevronRightIcon, EarthGlobeIcon, HeartIcon, ImagesIcon, @@ -24,7 +23,6 @@ import { compensationsId } from "./schemas/documents/compensations"; import { languageSettingsID } from "./schemas/documents/languageSettings"; import { pageBuilderID } from "./schemas/documents/pageBuilder"; import { brandAssetsID } from "./schemas/documents/siteSettings/brandAssets"; -import { brokenLinkID } from "./schemas/documents/siteSettings/brokenLink"; import { localeID } from "./schemas/documents/siteSettings/locale"; import { soMeLinksID } from "./schemas/documents/siteSettings/socialMediaProfiles"; import { customerCasesPageID } from "./schemas/documents/specialPages/customerCasesPage"; @@ -122,10 +120,6 @@ const siteSettingSection = (S: StructureBuilder) => .documentId(defaultSeoID) .title("Default SEO"), ), - S.listItem() - .title("Broken Links") - .icon(DoubleChevronRightIcon) - .child(S.documentTypeList(brokenLinkID).title("Redirects")), ]), ); diff --git a/studio/schema.ts b/studio/schema.ts index 91cdf055e..099a9e4f6 100644 --- a/studio/schema.ts +++ b/studio/schema.ts @@ -8,7 +8,6 @@ import compensations from "./schemas/documents/compensations"; import languageSettings from "./schemas/documents/languageSettings"; import pageBuilder from "./schemas/documents/pageBuilder"; import brandAssets from "./schemas/documents/siteSettings/brandAssets"; -import brokenLink from "./schemas/documents/siteSettings/brokenLink"; import locale from "./schemas/documents/siteSettings/locale"; import navigationManager from "./schemas/documents/siteSettings/navigationManager"; import socialMediaLinks from "./schemas/documents/siteSettings/socialMediaProfiles"; @@ -34,7 +33,6 @@ export const schema: { types: SchemaTypeDefinition[] } = { legalDocument, compensations, customerCasesPage, - brokenLink, benefitsByLocation, companyLocation, defaultSeo, diff --git a/studio/schemas/documents/siteSettings/brokenLink.ts b/studio/schemas/documents/siteSettings/brokenLink.ts deleted file mode 100644 index 1e24cbfd3..000000000 --- a/studio/schemas/documents/siteSettings/brokenLink.ts +++ /dev/null @@ -1,135 +0,0 @@ -import { SanityDocument, SlugRule } from "@sanity/types"; -import { type Slug, defineField, defineType } from "sanity"; - -import PrefixedSlugInput from "studio/components/slug/PrefixedSlugInput"; -import { compensationsId } from "studio/schemas/documents/compensations"; -import { pageBuilderID } from "studio/schemas/documents/pageBuilder"; - -const slugRequired = (rule: SlugRule) => - rule.required().custom((value: Slug | undefined) => { - if (!value || !value.current) return "Can't be blank"; - return true; - }); - -const requiredIfDestinationType = ( - type: string, - document: SanityDocument | undefined, - value: unknown, -) => { - const destination = document?.destination; - if ( - typeof destination === "object" && - destination !== null && - "type" in destination && - destination.type === type && - value === undefined - ) { - return "Can't be blank"; - } - return true; -}; - -export const brokenLinkID = "brokenLink"; - -const brokenLink = defineType({ - name: brokenLinkID, - title: "Broken Links", - type: "document", - fields: [ - defineField({ - name: "source", - title: "Source", - description: "The url slug to be redirected to the destination", - type: "slug", - validation: (rule) => slugRequired(rule), - components: { - input: (props) => PrefixedSlugInput({ prefix: "/", ...props }), - }, - }), - defineField({ - name: "destination", - title: "Destination", - type: "object", - fields: [ - defineField({ - name: "type", - title: "Type", - type: "string", - initialValue: "reference", - options: { - layout: "radio", - list: [ - { value: "reference", title: "Internal Page" }, - { value: "external", title: "External URL" }, - ], - }, - }), - defineField({ - name: "reference", - title: "Internal Page", - description: "Where should the user be redirected?", - type: "reference", - to: [{ type: pageBuilderID }, { type: compensationsId }], - hidden: ({ parent }) => parent?.type !== "reference", - validation: (rule) => - rule.custom((value, { document }) => - requiredIfDestinationType("reference", document, value), - ), - }), - defineField({ - name: "external", - title: "External URL", - description: "Where should the user be redirected?", - type: "url", - hidden: ({ parent }) => parent?.type !== "external", - validation: (rule) => - rule.custom((value, { document }) => - requiredIfDestinationType("external", document, value), - ), - }), - ], - }), - ], - preview: { - select: { - sourceSlug: "source.current", - destinationType: "destination.type", - destinationReferenceSlug: "destination.reference.slug.current", - destinationExternalURL: "destination.external", - }, - prepare({ - sourceSlug, - destinationType, - destinationReferenceSlug, - destinationExternalURL, - }) { - if ( - typeof sourceSlug !== "string" || - typeof destinationType !== "string" || - (destinationType === "reference" && - typeof destinationReferenceSlug !== "string") || - (destinationType === "external" && - typeof destinationExternalURL !== "string") - ) { - return {}; - } - const destination = { - reference: `/${destinationReferenceSlug}`, - external: destinationExternalURL, - }[destinationType]; - const title = - sourceSlug && destination - ? `/${sourceSlug} → ${destination}` - : undefined; - return { - title, - subtitle: { - reference: "Internal", - external: "External", - }[destinationType], - }; - }, - }, -}); - -export default brokenLink; diff --git a/studio/schemas/schemaTypes/slug.ts b/studio/schemas/schemaTypes/slug.ts index 90d32814f..4a9b99fdf 100644 --- a/studio/schemas/schemaTypes/slug.ts +++ b/studio/schemas/schemaTypes/slug.ts @@ -55,8 +55,7 @@ function createSlugField(source: string) { description: "Enter a unique URL path for the page. This path will be used in the website's address bar. " + "A URL path, also known as a slug, is a URL-friendly version of the page title, used to create " + - "a human-readable and search engine optimized URL for the content. " + - "Note that the slug can not be changed after publication, but alternative slugs can be defined via Redirects.", + "a human-readable and search engine optimized URL for the content. ", options: { source, maxLength: SLUG_MAX_LENGTH,