From 660abd3203be1169688d3c55bcc1f56acd587850 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Fri, 13 Sep 2024 13:39:37 +0200 Subject: [PATCH 1/3] feat(seoFallback): migrate from defaultSeo to seoFallback --- src/utils/seo.ts | 11 +++++++---- studio/lib/payloads/seoFallback.ts | 13 +++++++++++++ studio/lib/queries/companyDetails.ts | 6 ------ studio/lib/queries/seo.ts | 10 ++++++++++ studio/schemas/documents/companyInfo.ts | 8 -------- 5 files changed, 30 insertions(+), 18 deletions(-) create mode 100644 studio/lib/payloads/seoFallback.ts create mode 100644 studio/lib/queries/seo.ts diff --git a/src/utils/seo.ts b/src/utils/seo.ts index a0b72c1c6..a335002b0 100644 --- a/src/utils/seo.ts +++ b/src/utils/seo.ts @@ -4,6 +4,8 @@ import { urlFor } from "studio/lib/image"; import { COMPANY_INFO_QUERY } from "studio/lib/queries/companyDetails"; import { loadQuery } from "studio/lib/store"; import { PortableTextBlock } from "src/components/richText/RichText"; +import { FALLBACK_SEO_QUERY } from "../../studio/lib/queries/seo"; +import { SeoFallback } from "../../studio/lib/payloads/seoFallback"; type SeoData = { title: string; @@ -26,7 +28,6 @@ type CompanyInfo = { brandAssets: { favicon: string; }; - defaultSEO: SeoData; }; export const OPEN_GRAPH_IMAGE_DIMENSIONS = { @@ -84,14 +85,16 @@ export async function fetchCompanyInfo(): Promise { export async function generateMetadataFromSeo( seo: SeoData | null, ): Promise { + const { data: fallbackSeo } = + await loadQuery(FALLBACK_SEO_QUERY); const companyInfo = await fetchCompanyInfo(); const title = seo?.title || - companyInfo?.defaultSEO?.title || + fallbackSeo?.seo?.seoTitle || companyInfo?.siteMetadata?.siteName || "Variant"; - const description = seo?.description || companyInfo?.defaultSEO?.description; + const description = seo?.description || fallbackSeo.seo?.seoDescription; const keywords = seo?.keywords || ""; const favicon = companyInfo?.brandAssets?.favicon; @@ -105,7 +108,7 @@ export async function generateMetadataFromSeo( title: title, ...(description ? { description: description } : {}), })}`; - const sanityImageUrl = seo?.imageUrl || companyInfo?.defaultSEO?.imageUrl; + const sanityImageUrl = seo?.imageUrl || fallbackSeo.seo?.seoImageUrl; const sanityImageParams = `?${new URLSearchParams({ w: OPEN_GRAPH_IMAGE_DIMENSIONS.width.toString(), h: OPEN_GRAPH_IMAGE_DIMENSIONS.height.toString(), diff --git a/studio/lib/payloads/seoFallback.ts b/studio/lib/payloads/seoFallback.ts new file mode 100644 index 000000000..942aef266 --- /dev/null +++ b/studio/lib/payloads/seoFallback.ts @@ -0,0 +1,13 @@ +export type SeoFallback = { + _id: string; + _type: "seoFallback"; + _createdAt: string; + _updatedAt: string; + _rev: string; + seo?: { + seoTitle?: string; + seoDescription?: string; + seoKeywords?: string; + seoImageUrl?: string; + }; +}; diff --git a/studio/lib/queries/companyDetails.ts b/studio/lib/queries/companyDetails.ts index 85c72b648..05426005f 100644 --- a/studio/lib/queries/companyDetails.ts +++ b/studio/lib/queries/companyDetails.ts @@ -3,12 +3,6 @@ import { groq } from "next-sanity"; export const COMPANY_INFO_QUERY = groq`*[_type == "companyInfo"]{ brandAssets, siteMetadata, - defaultSEO { - "title": seoTitle, - "description": seoDescription, - "keywords": seoKeywords, - "imageUrl": seoImage.asset->url - }, legalPages, }[0]`; diff --git a/studio/lib/queries/seo.ts b/studio/lib/queries/seo.ts new file mode 100644 index 000000000..1be6978bc --- /dev/null +++ b/studio/lib/queries/seo.ts @@ -0,0 +1,10 @@ +import { groq } from "next-sanity"; + +export const FALLBACK_SEO_QUERY = groq`*[_type == "seoFallback"]{ + seo { + seoTitle, + seoDescription, + seoKeywords, + "seoImageUrl": seoImage.asset->url + } +}[0]`; diff --git a/studio/schemas/documents/companyInfo.ts b/studio/schemas/documents/companyInfo.ts index 7a4233d07..e70032961 100644 --- a/studio/schemas/documents/companyInfo.ts +++ b/studio/schemas/documents/companyInfo.ts @@ -79,14 +79,6 @@ const companyInfo = defineType({ }), ], }, - { - name: "defaultSEO", - type: "object", - title: "Default SEO Settings", - description: - "If page-specific SEO settings are not provided, these settings will be applied as default.", - fields: seo.fields, - }, ], preview: { prepare() { From f1fa62e034047887613f445d1757c36bafbe1946 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Mon, 16 Sep 2024 12:14:36 +0200 Subject: [PATCH 2/3] =?UTF-8?q?feat(defaultSeo):=20remove=20SEO=20parent?= =?UTF-8?q?=20item=20and=20rename=20Fallback=20SEO=20=E2=86=92=20Default?= =?UTF-8?q?=20SEO?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/seo.ts | 13 ++++++------ .../{seoFallback.ts => defaultSeo.ts} | 2 +- studio/lib/queries/seo.ts | 2 +- studio/schema.ts | 4 ++-- studio/schemas/deskStructure.ts | 20 ++++++------------- .../admin/{fallbackSeo.ts => defaultSeo.ts} | 8 ++++---- 6 files changed, 21 insertions(+), 28 deletions(-) rename studio/lib/payloads/{seoFallback.ts => defaultSeo.ts} (88%) rename studio/schemas/documents/admin/{fallbackSeo.ts => defaultSeo.ts} (83%) diff --git a/src/utils/seo.ts b/src/utils/seo.ts index a335002b0..12b62e920 100644 --- a/src/utils/seo.ts +++ b/src/utils/seo.ts @@ -4,8 +4,8 @@ import { urlFor } from "studio/lib/image"; import { COMPANY_INFO_QUERY } from "studio/lib/queries/companyDetails"; import { loadQuery } from "studio/lib/store"; import { PortableTextBlock } from "src/components/richText/RichText"; -import { FALLBACK_SEO_QUERY } from "../../studio/lib/queries/seo"; -import { SeoFallback } from "../../studio/lib/payloads/seoFallback"; +import { DEFAULT_SEO_QUERY } from "../../studio/lib/queries/seo"; +import { DefaultSeo } from "../../studio/lib/payloads/defaultSeo"; type SeoData = { title: string; @@ -85,8 +85,9 @@ export async function fetchCompanyInfo(): Promise { export async function generateMetadataFromSeo( seo: SeoData | null, ): Promise { - const { data: fallbackSeo } = - await loadQuery(FALLBACK_SEO_QUERY); + const { data: fallbackSeo } = await loadQuery( + DEFAULT_SEO_QUERY, + ); const companyInfo = await fetchCompanyInfo(); const title = @@ -94,7 +95,7 @@ export async function generateMetadataFromSeo( fallbackSeo?.seo?.seoTitle || companyInfo?.siteMetadata?.siteName || "Variant"; - const description = seo?.description || fallbackSeo.seo?.seoDescription; + const description = seo?.description || fallbackSeo?.seo?.seoDescription; const keywords = seo?.keywords || ""; const favicon = companyInfo?.brandAssets?.favicon; @@ -108,7 +109,7 @@ export async function generateMetadataFromSeo( title: title, ...(description ? { description: description } : {}), })}`; - const sanityImageUrl = seo?.imageUrl || fallbackSeo.seo?.seoImageUrl; + const sanityImageUrl = seo?.imageUrl || fallbackSeo?.seo?.seoImageUrl; const sanityImageParams = `?${new URLSearchParams({ w: OPEN_GRAPH_IMAGE_DIMENSIONS.width.toString(), h: OPEN_GRAPH_IMAGE_DIMENSIONS.height.toString(), diff --git a/studio/lib/payloads/seoFallback.ts b/studio/lib/payloads/defaultSeo.ts similarity index 88% rename from studio/lib/payloads/seoFallback.ts rename to studio/lib/payloads/defaultSeo.ts index 942aef266..8e184453e 100644 --- a/studio/lib/payloads/seoFallback.ts +++ b/studio/lib/payloads/defaultSeo.ts @@ -1,4 +1,4 @@ -export type SeoFallback = { +export type DefaultSeo = { _id: string; _type: "seoFallback"; _createdAt: string; diff --git a/studio/lib/queries/seo.ts b/studio/lib/queries/seo.ts index 1be6978bc..2a2e5f0b2 100644 --- a/studio/lib/queries/seo.ts +++ b/studio/lib/queries/seo.ts @@ -1,6 +1,6 @@ import { groq } from "next-sanity"; -export const FALLBACK_SEO_QUERY = groq`*[_type == "seoFallback"]{ +export const DEFAULT_SEO_QUERY = groq`*[_type == "seoFallback"]{ seo { seoTitle, seoDescription, diff --git a/studio/schema.ts b/studio/schema.ts index 83e3136e7..557d904a1 100644 --- a/studio/schema.ts +++ b/studio/schema.ts @@ -15,7 +15,7 @@ import companyLocation from "./schemas/documents/companyLocation"; import compensations from "./schemas/documents/compensations"; import redirect from "./schemas/documents/redirect"; import benefitsByLocation from "./schemas/objects/compensations/benefitsByLocation"; -import seoFallback from "./schemas/documents/admin/fallbackSeo"; +import defaultSeo from "./schemas/documents/admin/defaultSeo"; export const schema: { types: SchemaTypeDefinition[] } = { types: [ @@ -35,6 +35,6 @@ export const schema: { types: SchemaTypeDefinition[] } = { redirect, benefitsByLocation, companyLocation, - seoFallback, + defaultSeo, ], }; diff --git a/studio/schemas/deskStructure.ts b/studio/schemas/deskStructure.ts index 5acb0b0f9..c7a2c3b5c 100644 --- a/studio/schemas/deskStructure.ts +++ b/studio/schemas/deskStructure.ts @@ -20,7 +20,7 @@ import { legalDocumentID } from "./documents/legalDocuments"; import { compensationsId } from "./documents/compensations"; import { redirectId } from "./documents/redirect"; import { companyLocationID } from "./documents/companyLocation"; -import { seoFallbackID } from "./documents/admin/fallbackSeo"; +import { defaultSeoID } from "./documents/admin/defaultSeo"; // Admin Section const adminSection = (S: StructureBuilder) => @@ -80,21 +80,13 @@ const siteSettingSection = (S: StructureBuilder) => S.document().schemaType(soMeLinksID).documentId(soMeLinksID), ), S.listItem() - .title("SEO Configurations") + .title("Default SEO") .icon(SearchIcon) .child( - S.list() - .title("SEO Configurations") - .items([ - S.listItem() - .title("Fallback SEO") - .child( - S.document() - .schemaType(seoFallbackID) - .documentId(seoFallbackID) - .title("Fallback SEO"), - ), - ]), + S.document() + .schemaType(defaultSeoID) + .documentId(defaultSeoID) + .title("Default SEO"), ), S.listItem() .title("Broken Links") diff --git a/studio/schemas/documents/admin/fallbackSeo.ts b/studio/schemas/documents/admin/defaultSeo.ts similarity index 83% rename from studio/schemas/documents/admin/fallbackSeo.ts rename to studio/schemas/documents/admin/defaultSeo.ts index 6508d876d..b58fb0824 100644 --- a/studio/schemas/documents/admin/fallbackSeo.ts +++ b/studio/schemas/documents/admin/defaultSeo.ts @@ -1,10 +1,10 @@ import { defineField, defineType } from "sanity"; import seo from "studio/schemas/objects/seo"; -export const seoFallbackID = "seoFallback"; +export const defaultSeoID = "seoFallback"; -const seoFallback = defineType({ - name: seoFallbackID, +const defaultSeo = defineType({ + name: defaultSeoID, type: "document", title: "SEO Configurations", description: @@ -29,4 +29,4 @@ const seoFallback = defineType({ }, }); -export default seoFallback; +export default defaultSeo; From 5fb97a173a84da9fd32138cddde5bfca16c6e651 Mon Sep 17 00:00:00 2001 From: Mathias Oterhals Myklebust Date: Mon, 16 Sep 2024 12:17:29 +0200 Subject: [PATCH 3/3] =?UTF-8?q?refactor(seo):=20fallbackSeo=20=E2=86=92=20?= =?UTF-8?q?defaultSeo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/utils/seo.ts | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/utils/seo.ts b/src/utils/seo.ts index 12b62e920..ff79070e0 100644 --- a/src/utils/seo.ts +++ b/src/utils/seo.ts @@ -85,17 +85,17 @@ export async function fetchCompanyInfo(): Promise { export async function generateMetadataFromSeo( seo: SeoData | null, ): Promise { - const { data: fallbackSeo } = await loadQuery( + const { data: defaultSeo } = await loadQuery( DEFAULT_SEO_QUERY, ); const companyInfo = await fetchCompanyInfo(); const title = seo?.title || - fallbackSeo?.seo?.seoTitle || + defaultSeo?.seo?.seoTitle || companyInfo?.siteMetadata?.siteName || "Variant"; - const description = seo?.description || fallbackSeo?.seo?.seoDescription; + const description = seo?.description || defaultSeo?.seo?.seoDescription; const keywords = seo?.keywords || ""; const favicon = companyInfo?.brandAssets?.favicon; @@ -109,7 +109,7 @@ export async function generateMetadataFromSeo( title: title, ...(description ? { description: description } : {}), })}`; - const sanityImageUrl = seo?.imageUrl || fallbackSeo?.seo?.seoImageUrl; + const sanityImageUrl = seo?.imageUrl || defaultSeo?.seo?.seoImageUrl; const sanityImageParams = `?${new URLSearchParams({ w: OPEN_GRAPH_IMAGE_DIMENSIONS.width.toString(), h: OPEN_GRAPH_IMAGE_DIMENSIONS.height.toString(),