Skip to content

Commit

Permalink
feat(defaultSeo): remove SEO parent item and rename Fallback SEO → De…
Browse files Browse the repository at this point in the history
…fault SEO
  • Loading branch information
mathiazom committed Sep 16, 2024
1 parent 660abd3 commit f1fa62e
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 28 deletions.
13 changes: 7 additions & 6 deletions src/utils/seo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,16 +85,17 @@ export async function fetchCompanyInfo(): Promise<CompanyInfo | null> {
export async function generateMetadataFromSeo(
seo: SeoData | null,
): Promise<Metadata> {
const { data: fallbackSeo } =
await loadQuery<SeoFallback>(FALLBACK_SEO_QUERY);
const { data: fallbackSeo } = await loadQuery<DefaultSeo | null>(
DEFAULT_SEO_QUERY,
);
const companyInfo = await fetchCompanyInfo();

const title =
seo?.title ||
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;
Expand All @@ -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(),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
export type SeoFallback = {
export type DefaultSeo = {
_id: string;
_type: "seoFallback";
_createdAt: string;
Expand Down
2 changes: 1 addition & 1 deletion studio/lib/queries/seo.ts
Original file line number Diff line number Diff line change
@@ -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,
Expand Down
4 changes: 2 additions & 2 deletions studio/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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: [
Expand All @@ -35,6 +35,6 @@ export const schema: { types: SchemaTypeDefinition[] } = {
redirect,
benefitsByLocation,
companyLocation,
seoFallback,
defaultSeo,
],
};
20 changes: 6 additions & 14 deletions studio/schemas/deskStructure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) =>
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
@@ -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:
Expand All @@ -29,4 +29,4 @@ const seoFallback = defineType({
},
});

export default seoFallback;
export default defaultSeo;

0 comments on commit f1fa62e

Please sign in to comment.