Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v3 - dynamic page basic title #845

Merged
merged 1 commit into from
Oct 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion studio/lib/interfaces/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@ export interface PageBuilder {
_type: string;
_updatedAt: string;
language: string;
page: string;
basicTitle: string;
sections: Section[];
slug: Slug;
seo: SeoData;
Expand Down
1 change: 1 addition & 0 deletions studio/lib/queries/pages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export const SEO_FRAGMENT = groq`
export const PAGE_FRAGMENT = groq`
...,
"slug": ${translatedFieldFragment("slug")},
"basicTitle": ${translatedFieldFragment("basicTitle")},
${LANGUAGE_FIELD_FRAGMENT},
${SECTIONS_FRAGMENT},
${SEO_FRAGMENT}
Expand Down
34 changes: 17 additions & 17 deletions studio/schemas/documents/pageBuilder.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { defineField, defineType } from "sanity";

import { StringInputWithCharacterCount } from "studio/components/stringInputWithCharacterCount/StringInputWithCharacterCount";
import { isInternationalizedString } from "studio/lib/interfaces/global";
import { titleID } from "studio/schemas/fields/text";
import article from "studio/schemas/objects/sections/article";
import callout from "studio/schemas/objects/sections/callout";
import callToAction from "studio/schemas/objects/sections/callToAction";
Expand All @@ -12,7 +12,7 @@ import imageSection from "studio/schemas/objects/sections/image";
import logoSalad from "studio/schemas/objects/sections/logoSalad";
import testimonals from "studio/schemas/objects/sections/testimonials";
import seo from "studio/schemas/objects/seo";
import { pageSlug } from "studio/schemas/schemaTypes/slug";
import { titleSlug } from "studio/schemas/schemaTypes/slug";
import { firstTranslation } from "studio/utils/i18n";

export const pageBuilderID = "pageBuilder";
Expand All @@ -22,20 +22,15 @@ const pageBuilder = defineType({
type: "document",
title: "Dynamic pages",
fields: [
defineField({
name: "page",
title: "Page name",
{
name: titleID.basic,
type: "internationalizedArrayString",
title: "Page Title",
description:
"Enter a distinctive name for the dynamic page to help content editors easily identify and manage it. This name is used internally and is not visible on your website.",
type: "string",
validation: (rule) => rule.required().max(30),
components: {
input: (props) =>
StringInputWithCharacterCount({ ...props, maxCount: 30 }),
},
}),
"Enter the primary title that will be displayed in Sanity and the breadcrumb trail at the top of the page.",
},
{
...pageSlug,
...titleSlug,
type: "internationalizedArrayString",
},
seo,
Expand All @@ -59,17 +54,22 @@ const pageBuilder = defineType({
],
preview: {
select: {
title: "page",
slug: pageSlug.name,
title: titleID.basic,
slug: titleSlug.name,
},
prepare({ title, slug }) {
if (!isInternationalizedString(title)) {
throw new TypeError(
`Expected 'title' to be InternationalizedString, was ${typeof title}`,
);
}
if (!isInternationalizedString(slug)) {
throw new TypeError(
`Expected 'slug' to be InternationalizedString, was ${typeof slug}`,
);
}
return {
title: title ?? undefined,
title: firstTranslation(title) ?? undefined,
subtitle: firstTranslation(slug) ?? undefined,
};
},
Expand Down