xcollantes / portfolio

Personal portfolio of work.
https://portfolio-xcollantes.vercel.app
Apache License 2.0
0 stars 0 forks source link

Make iframes able to be in blogs #51

Closed xcollantes closed 1 year ago

xcollantes commented 1 year ago

Blogs should have embedded content since this is common for users to see in blogs and enriches the user experience.

Challenge

ReactMarkdown does not natively support usage of HTML element. All elements will be treated as Markdown.

xcollantes commented 1 year ago

Solution

https://stackoverflow.com/a/70548866/8278075

Use rehype as a plugin for ReactMarkdown:

<ReactMarkdown
          components={ReactMarkdownRules()}
          rehypePlugins={[rehypeRaw] as any}
        >
          {markdownBody}
</ReactMarkdown>

You would add a blog entry in the Markdown file:

   <div
     style="padding-bottom:56.25%; position:relative; display:block; width: 100%"
   >
     <iframe
       width="100%"
       height="100%"
       src="https://youtu.be/j5a0jTc9S10?si=eGX-bRyQGBp4cAed"
       frameborder="0"
       allowfullscreen=""
       style="position:absolute; top:0; left: 0"
     >
     </iframe>
   </div>
xcollantes commented 1 year ago

All iframes must be responsive as we intend for users to mostly view site on mobile.