File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff 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 ( / \. ( w m v | m p 4 ) $ / 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 } ;
You can’t perform that action at this time.
0 commit comments