diff --git a/_posts/complementing-python-with-rust.mdx b/_posts/complementing-python-with-rust.mdx index dd64d78..53c6e73 100644 --- a/_posts/complementing-python-with-rust.mdx +++ b/_posts/complementing-python-with-rust.mdx @@ -259,3 +259,9 @@ Something I didn’t explore was to check if the benefits will be much higher fo There are a few talks that I borrowed ideas from — [here](https://www.youtube.com/watch?v=-ylbuEzkG4M), [here](https://blog.sentry.io/2016/10/19/fixing-python-performance-with-rust.html) and [here](https://www.youtube.com/watch?v=3CwJ0MH-4MA). The first talk takes a different approach and uses [rust-cpython](https://github.com/dgrunwald/rust-cpython) for binding Python and Rust. You can also watch a recording of the video, but if you have already read so far, there is nothing new in the video. I start at 3 mins. + + diff --git a/components/post-body.tsx b/components/post-body.tsx index e8b0d67..c05cba6 100644 --- a/components/post-body.tsx +++ b/components/post-body.tsx @@ -1,5 +1,6 @@ import { MDXRemote, MDXRemoteSerializeResult } from 'next-mdx-remote' import Quotation from './quotation' +import YoutubeEmbed from './youtube-embed' type PostBodyProps = { source: MDXRemoteSerializeResult @@ -7,6 +8,7 @@ type PostBodyProps = { const components = { Quotation, + YoutubeEmbed, } const PostBody: React.FC = ({ source }) => { diff --git a/components/youtube-embed.tsx b/components/youtube-embed.tsx new file mode 100644 index 0000000..c21e698 --- /dev/null +++ b/components/youtube-embed.tsx @@ -0,0 +1,22 @@ +interface YoutubeEmbedProps { + title: string + id: string + start?: number +} + +const YoutubeEmbed: React.FC = ({ title, id, start }) => { + return ( + + ) +} + +export default YoutubeEmbed diff --git a/lib/markdownToHtml.ts b/lib/markdownToHtml.ts index 68123cd..2ad6691 100644 --- a/lib/markdownToHtml.ts +++ b/lib/markdownToHtml.ts @@ -3,40 +3,6 @@ import remarkDirective from 'remark-directive' import remarkHtml from 'remark-html' import remarkParse from 'remark-parse' import remarkPrism from 'remark-prism' -import { visit } from 'unist-util-visit' - -function youtubeDirective(node: any) { - const data = node.data || (node.data = {}) - const attributes = node.attributes || {} - const id = attributes.id - if (node.type === 'textDirective') - console.warn('Text directives for `youtube` not supported', node) - if (!id) console.warn('Missing video id', node) - data.hName = 'iframe' - data.hProperties = { - src: 'https://www.youtube.com/embed/' + id, - height: '300px', - width: '100%', - frameborder: '0', - allow: - 'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture', - allowfullscreen: true, - } -} - -function onDirective() { - return (tree: any) => { - visit( - tree, - ['textDirective', 'leafDirective', 'containerDirective'], - (node) => { - if (node.name === 'youtube') { - return youtubeDirective(node) - } - }, - ) - } -} export default async function markdownToHtml( markdown: string, @@ -44,7 +10,6 @@ export default async function markdownToHtml( const r = remark() r.use(remarkParse) r.use(remarkDirective) - r.use(onDirective) r.use(remarkPrism) r.use(remarkHtml, { sanitize: false }) return (await r.process(markdown)).toString()