-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCommonPage.tsx
72 lines (60 loc) · 1.99 KB
/
CommonPage.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
import type React from "react";
import { documentToReactComponents } from "@contentful/rich-text-react-renderer";
import {
useContentfulInspectorMode,
useContentfulLiveUpdates,
} from "@contentful/live-preview/react";
import type { SitemapItem, PageData } from "@/helpers/types";
import { LOCALE } from "@/helpers/constants";
import pageRenderOptions from "@/helpers/rendering";
import Hero from "@/components/Hero/Hero";
import { Breadcrumbs, SEO } from "@/components";
interface Props {
page: SitemapItem;
parent?: SitemapItem;
breadcrumbs: Array<SitemapItem>;
data: PageData;
children?: React.JSX.Element | React.JSX.Element[];
wide?: boolean;
}
const CommonPage = ({ page, parent, breadcrumbs, data, children, wide = false }: Props) => {
const backgroundImage = data?.background?.url ? `url(${data.background.url})` : undefined;
const previewProps = useContentfulInspectorMode();
const previewData = useContentfulLiveUpdates({
sys: { id: data.id },
fields: { content: { [LOCALE]: data.content } },
});
return (
<>
<SEO
page={{ ...page, description: data.description ?? undefined }}
breadcrumbs={breadcrumbs}
images={
data?.image
? [
{
url: data?.image.url,
width: data?.image.width,
height: data?.image.height,
},
]
: undefined
}
/>
<Hero title={page.title} subtitle={parent?.title} background={data?.image?.url} wide={wide} />
<Breadcrumbs items={breadcrumbs} style={wide ? "wide" : "normal"} />
<article
className={`content ${wide ? "wide" : ""}`}
style={{ backgroundImage }}
{...previewProps({
entryId: previewData.sys.id as string,
fieldId: "content",
})}
>
{data.content && documentToReactComponents(data.content, pageRenderOptions)}
{children}
</article>
</>
);
};
export default CommonPage;