Skip to content

Commit 5308818

Browse files
authored
Fixed embedded video rendering in article page (#978)
1 parent ef3dd28 commit 5308818

1 file changed

Lines changed: 18 additions & 3 deletions

File tree

src/posts/articles/ArticlePage.tsx

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,13 +49,28 @@ const Content = (props: any) => {
4949
const { html, children } = props;
5050
const body = JSON.parse(html.raw);
5151

52-
const findImg = (id: string) => html.references.find((el: any) => el?.contentful_id && el.contentful_id === id);
52+
const findAsset = (id: string) =>
53+
html.references.find((el: any) => el?.contentful_id && el.contentful_id === id);
5354

5455
const options = {
5556
renderNode: {
5657
[BLOCKS.EMBEDDED_ASSET]: (node: any) => {
57-
const image = findImg(node.data.target.sys.id);
58-
return `<img src=${image.url} alt=${image.title}/>`;
58+
const asset = findAsset(node.data.target.sys.id);
59+
if (!asset) return '';
60+
61+
const url = asset.url;
62+
const title = asset.title || '';
63+
64+
if (url.match(/\.(wmv|mp4)$/i)) {
65+
return `
66+
<video controls style="display:block;max-width:100%;height:auto;margin:1.5rem auto;">
67+
<source src="${url}" />
68+
Your browser does not support the video tag.
69+
</video>
70+
`;
71+
}
72+
73+
return `<img src="${url}" alt="${title}" />`;
5974
},
6075
},
6176
};

0 commit comments

Comments
 (0)