Skip to content

Commit 5a52177

Browse files
authored
Merge pull request #243 from dotCMS/video-fix-for-getting-started
Tweaks to make videos in block editor fields display in GS pages
2 parents 9a9c7df + 8f6e894 commit 5a52177

2 files changed

Lines changed: 19 additions & 16 deletions

File tree

components/content-types/webPageContent.tsx

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2,27 +2,23 @@ import React from 'react';
22
import { isJSON } from '@/util/utils';
33
import { DotBlockEditor } from '../shared/dotBlockEditor';
44
interface WebPageContentProps {
5-
title: string;
6-
body: string;
5+
title?: string;
6+
body?: string | { json?: string; content?: unknown[] };
77
}
88

99
const WebPageContent: React.FC<WebPageContentProps> = (contentlet) => {
1010
const { title, body } = contentlet;
11+
const raw = (body as any)?.json ?? body;
12+
const blocks = typeof raw === "string" && isJSON(raw) ? JSON.parse(raw) : raw;
1113

1214
return (
1315
<article className="w-full">
14-
1516
<div className="prose dark:prose-invert max-w-none">
16-
{isJSON(body) ? (
17-
<DotBlockEditor
18-
blocks={typeof body === 'string' ? JSON.parse(body) : body}
19-
customRenderers={{}}
20-
/>
21-
) : (
22-
<>
23-
<div dangerouslySetInnerHTML={{ __html: body }} />
24-
</>
25-
)}
17+
{blocks?.content != null ? (
18+
<DotBlockEditor blocks={blocks} customRenderers={{}} />
19+
) : typeof body === "string" ? (
20+
<div dangerouslySetInnerHTML={{ __html: body }} />
21+
) : null}
2622
</div>
2723
</article>
2824
);

components/shared/dotBlockEditor.js

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -148,15 +148,22 @@ function VideoContentlet({ node }) {
148148
}
149149

150150
/**
151-
* dotVideo block renderer — matches marketing site pattern: pass attrs.data into Video component.
152-
* Custom renderer receives { node }; node.attrs.data holds the video/contentlet data.
151+
* dotVideo block renderer — pass contentlet (attrs.data) plus resolved attrs (src, mimeType, etc.) into Video.
152+
* Block editor may put the resolved URL in node.attrs.src; contentlet has asset/thumbnail etc.
153153
*/
154154
export const VidContent = (props) => {
155155
const attrs = props.attrs || props.node?.attrs || {};
156156
const data = attrs.data ?? attrs;
157+
const videoProps = {
158+
...data,
159+
src: attrs.src ?? data.src,
160+
mimeType: attrs.mimeType ?? data.mimeType,
161+
width: attrs.width ?? data.width,
162+
height: attrs.height ?? data.height,
163+
};
157164
return (
158165
<div className="my-1">
159-
<Video {...data} />
166+
<Video {...videoProps} />
160167
</div>
161168
);
162169
};

0 commit comments

Comments
 (0)