Skip to content

Commit

Permalink
feat: marketing page space
Browse files Browse the repository at this point in the history
  • Loading branch information
juliankoehn committed Feb 13, 2025
1 parent f234e10 commit 277a105
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 0 deletions.
55 changes: 55 additions & 0 deletions customtypes/marketing/index.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
{
"format": "page",
"id": "marketing",
"label": "Marketing",
"repeatable": true,
"status": true,
"json": {
"Main": {
"uid": {
"type": "UID",
"config": {
"label": "UID"
}
},
"slices": {
"type": "Slices",
"fieldset": "Slice Zone",
"config": {
"choices": {
"hero": {
"type": "SharedSlice"
}
}
}
}
},
"SEO & Metadata": {
"meta_title": {
"config": {
"label": "Meta Title",
"placeholder": "A title of the page used for social media and search engines"
},
"type": "Text"
},
"meta_description": {
"config": {
"label": "Meta Description",
"placeholder": "A brief summary of the page"
},
"type": "Text"
},
"meta_image": {
"config": {
"constraint": {
"height": 1260,
"width": 2400
},
"label": "Meta Image",
"thumbnails": []
},
"type": "Image"
}
}
}
}
69 changes: 69 additions & 0 deletions prismicio-types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -900,6 +900,71 @@ export type LegalHomeDocument<Lang extends string = string> =
Lang
>;

type MarketingDocumentDataSlicesSlice = HeroSlice;

/**
* Content for Marketing documents
*/
interface MarketingDocumentData {
/**
* Slice Zone field in *Marketing*
*
* - **Field Type**: Slice Zone
* - **Placeholder**: *None*
* - **API ID Path**: marketing.slices[]
* - **Tab**: Main
* - **Documentation**: https://prismic.io/docs/field#slices
*/
slices: prismic.SliceZone<MarketingDocumentDataSlicesSlice> /**
* Meta Title field in *Marketing*
*
* - **Field Type**: Text
* - **Placeholder**: A title of the page used for social media and search engines
* - **API ID Path**: marketing.meta_title
* - **Tab**: SEO & Metadata
* - **Documentation**: https://prismic.io/docs/field#key-text
*/;
meta_title: prismic.KeyTextField;

/**
* Meta Description field in *Marketing*
*
* - **Field Type**: Text
* - **Placeholder**: A brief summary of the page
* - **API ID Path**: marketing.meta_description
* - **Tab**: SEO & Metadata
* - **Documentation**: https://prismic.io/docs/field#key-text
*/
meta_description: prismic.KeyTextField;

/**
* Meta Image field in *Marketing*
*
* - **Field Type**: Image
* - **Placeholder**: *None*
* - **API ID Path**: marketing.meta_image
* - **Tab**: SEO & Metadata
* - **Documentation**: https://prismic.io/docs/field#image
*/
meta_image: prismic.ImageField<never>;
}

/**
* Marketing document from Prismic
*
* - **API ID**: `marketing`
* - **Repeatable**: `true`
* - **Documentation**: https://prismic.io/docs/custom-types
*
* @typeParam Lang - Language API ID of the document.
*/
export type MarketingDocument<Lang extends string = string> =
prismic.PrismicDocumentWithUID<
Simplify<MarketingDocumentData>,
"marketing",
Lang
>;

type PageDocumentDataSlicesSlice =
| BenefitsSlice
| FeaturesSlice
Expand Down Expand Up @@ -1278,6 +1343,7 @@ export type AllDocumentTypes =
| LayoutDocument
| LegalDocument
| LegalHomeDocument
| MarketingDocument
| PageDocument
| ServicesDocument
| SettingsDocument
Expand Down Expand Up @@ -3428,6 +3494,9 @@ declare module "@prismicio/client" {
LegalHomeDocument,
LegalHomeDocumentData,
LegalHomeDocumentDataSlicesSlice,
MarketingDocument,
MarketingDocumentData,
MarketingDocumentDataSlicesSlice,
PageDocument,
PageDocumentData,
PageDocumentDataSlicesSlice,
Expand Down
61 changes: 61 additions & 0 deletions src/app/(frontend)/[lang]/(pages)/[uid]/page.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
import { createClient } from "@/prismicio";
import { components } from "@/slices";
import { asImageSrc, isFilled } from "@prismicio/client";
import { SliceZone } from "@prismicio/react";
import type { Metadata } from "next";
import { notFound } from "next/navigation";

type Params = {
lang: string;
uid: string;
};

type Props = {
params: Promise<Params>;
};

export default async function PrismigPage(props: Props) {
const params = await props.params;

const client = createClient();
const page = await client
.getByUID("marketing", params.uid, { lang: params.lang })
.catch(() => notFound());

return <SliceZone slices={page.data.slices} components={components} />;
}

export async function generateMetadata({ params }: Props): Promise<Metadata> {
const { uid, lang } = await params;
const client = createClient();
const page = await client
.getByUID("marketing", uid, { lang })
.catch(() => notFound());

return {
title: page.data.meta_title,
description: page.data.meta_description,
openGraph: {
title: isFilled.keyText(page.data.meta_title)
? page.data.meta_title
: undefined,
description: isFilled.keyText(page.data.meta_description)
? page.data.meta_description
: undefined,
images: isFilled.image(page.data.meta_image)
? [asImageSrc(page.data.meta_image)]
: undefined,
},
};
}

export async function generateStaticParams() {
const client = createClient();
const pages = await client.getAllByType("marketing", {
lang: "*",
});

return pages.map((page) => {
return { uid: page.uid, lang: page.lang };
});
}
4 changes: 4 additions & 0 deletions src/prismicio.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,10 @@ const routes: prismic.ClientConfig["routes"] = [
type: "enterprise_home",
path: "/:lang/enterprise",
},
{
type: "marketing",
path: "/:lang/:uid",
},
{
type: "blog_home",
path: "/:lang/blog",
Expand Down

0 comments on commit 277a105

Please sign in to comment.