<?xml version="1.0" encoding="UTF-8"?><rss version="2.0" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Posts tagged #oembed</title><description>The latest posts tagged with oembed on queen.raae.codes</description><link>https://queen.raae.codes/tag/oembed/</link><item><title>📄 🖼 ~ What is Gatsby Remark oEmbed, and how does it work?</title><link>https://queen.raae.codes/2022-04-26-gatsby-remark-oembed/</link><guid isPermaLink="true">https://queen.raae.codes/2022-04-26-gatsby-remark-oembed/</guid><description>As mentioned yesterday I plan to get a good chunk of work done on the next version of the gatsby-remark-oembed plugin this week. But you might wonder what even…</description><pubDate>Tue, 26 Apr 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;As mentioned &lt;a href=&quot;/2022-04-25-this-week/&quot;&gt;yesterday&lt;/a&gt; I plan to get a good chunk of work done on the next version of the &lt;a href=&quot;https://github.com/queen-raae/gatsby-remark-oembed&quot;&gt;gatsby-remark-oembed&lt;/a&gt; plugin this week.&lt;/p&gt;
&lt;p&gt;But you might wonder what even is that and how does it work?&lt;/p&gt;
&lt;h2&gt;What is Gatsby Remark oEmbed?&lt;/h2&gt;
&lt;p&gt;The goal of Gatsby Remark oEmbed is to let you drop in a link to embeddable content:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-md&quot;&gt;Embed anything that supports the oEmbed protocol!

https://youtu.be/VhrOe0X_oA8

By adding a link on its own line!
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;And have it show up like so on your Gatsby site:&lt;/p&gt;
&lt;p&gt;&lt;img src=&quot;./oEmbed-example.png&quot; alt=&quot;YouTube embedded in the html&quot;&gt;&lt;/p&gt;
&lt;h2&gt;How does it work?&lt;/h2&gt;
&lt;p&gt;The plugin is a &lt;a href=&quot;https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-remark&quot;&gt;gatsby-transformer-remark&lt;/a&gt; sub-plugin. Meaning it will only do work on MarkdownRemark-nodes.&lt;/p&gt;
&lt;p&gt;For each MarkdownRemark-node Gatsby Remark oEmbed finds the standalone links, checks the oEmbed provider list for a match, and swaps the link out for the result coming back from the matching provider&apos;s oEmbed endpoint.&lt;/p&gt;
&lt;p&gt;In the example above, that means swapping:&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;https://youtu.be/VhrOe0X_oA8
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;with the &lt;code&gt;html&lt;/code&gt;-value of the oEmbed response from YouTube:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &amp;quot;title&amp;quot;: &amp;quot;\ud83d\udd34 \ud83c\udff4\u200d\u2620\ufe0f Source YouTube information using oEmbed, no YouTube API Key needed \u00b7 #GatsbyJS Deep Dive&amp;quot;,
  &amp;quot;author_name&amp;quot;: &amp;quot;Queen Raae&amp;quot;,
  &amp;quot;author_url&amp;quot;: &amp;quot;https://www.youtube.com/c/QueenRaae&amp;quot;,
  &amp;quot;type&amp;quot;: &amp;quot;video&amp;quot;,
  &amp;quot;height&amp;quot;: 113,
  &amp;quot;width&amp;quot;: 200,
  &amp;quot;version&amp;quot;: &amp;quot;1.0&amp;quot;,
  &amp;quot;provider_name&amp;quot;: &amp;quot;YouTube&amp;quot;,
  &amp;quot;provider_url&amp;quot;: &amp;quot;https://www.youtube.com/&amp;quot;,
  &amp;quot;thumbnail_height&amp;quot;: 360,
  &amp;quot;thumbnail_width&amp;quot;: 480,
  &amp;quot;thumbnail_url&amp;quot;: &amp;quot;https://i.ytimg.com/vi/VhrOe0X_oA8/hqdefault.jpg&amp;quot;,
  &amp;quot;html&amp;quot;: &amp;quot;\u003ciframe width=\u0022200\u0022 height=\u0022113\u0022 src=\u0022https://www.youtube.com/embed/VhrOe0X_oA8?feature=oembed\u0022 frameborder=\u00220\u0022 allow=\u0022accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\u0022 allowfullscreen\u003e\u003c/iframe\u003e&amp;quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;that we got by calling YouTube&apos;s oEmbed endpoint with the original standalone link: https://www.youtube.com/oembed?url=https://youtu.be/VhrOe0X_oA8.&lt;/p&gt;
&lt;p&gt; &lt;/p&gt;
&lt;ul&gt;
&lt;li&gt;If this sounds interesting to you and you would like to contribute, shoot me a reply, and I&apos;ll loop you in!&lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt; &lt;br&gt;
All the best,&lt;br&gt;
Queen Raae&lt;/p&gt;
</content:encoded></item><item><title>🔴 🏴‍☠️ ~ Source YouTube information using oEmbed, no YouTube API Key needed</title><link>https://queen.raae.codes/2022-01-21-yt-oembed/</link><guid isPermaLink="true">https://queen.raae.codes/2022-01-21-yt-oembed/</guid><description>In yesterday&apos;s unauthorized and rum-fueled treasure hunts in the sharky waters around the Gatsby islands, we looked closely at sourcing content nodes with data…</description><pubDate>Fri, 21 Jan 2022 00:00:00 GMT</pubDate><content:encoded>&lt;p&gt;In yesterday&apos;s unauthorized and rum-fueled treasure hunts in the sharky waters around the Gatsby islands, we looked closely at &lt;a href=&quot;https://youtu.be/VhrOe0X_oA8&quot;&gt;sourcing content nodes&lt;/a&gt; with data from the YouTube oEmbed endpoint.&lt;/p&gt;
&lt;p&gt;&lt;a href=&quot;https://oembed.com/&quot;&gt;oEmbed&lt;/a&gt; is likely one of the most underappreciated concepts of the open web. I first encountered it when WordPress added support back in my uni days; let&apos;s just say it been awhile 👵&lt;/p&gt;
&lt;p&gt;A simple yet powerful concept that I think would benefit from more awareness.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;Have you heard about or used oEmbed before?&lt;/strong&gt;&lt;/p&gt;
&lt;h2&gt;oEmbed Examples&lt;/h2&gt;
&lt;p&gt;A provider: YouTube, SoundCloud, Issuu, Flickr, or your blog provides an oEmbed endpoint that accepts at a minimum an URL and returns embeddable content in return.&lt;/p&gt;
&lt;p&gt;A GET request to &lt;code&gt;https://www.flickr.com/services/oembed/?url=http://www.flickr.com/photos/bees/2341623661/&lt;/code&gt; returns:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &amp;quot;version&amp;quot;: &amp;quot;1.0&amp;quot;,
  &amp;quot;type&amp;quot;: &amp;quot;photo&amp;quot;,
  &amp;quot;width&amp;quot;: 240,
  &amp;quot;height&amp;quot;: 160,
  &amp;quot;title&amp;quot;: &amp;quot;ZB8T0193&amp;quot;,
  &amp;quot;url&amp;quot;: &amp;quot;http://farm4.static.flickr.com/3123/2341623661_7c99f48bbf_m.jpg&amp;quot;,
  &amp;quot;author_name&amp;quot;: &amp;quot;Bees&amp;quot;,
  &amp;quot;author_url&amp;quot;: &amp;quot;http://www.flickr.com/photos/bees/&amp;quot;,
  &amp;quot;provider_name&amp;quot;: &amp;quot;Flickr&amp;quot;,
  &amp;quot;provider_url&amp;quot;: &amp;quot;http://www.flickr.com/&amp;quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Or more interestingly in our case, a GET Request to &lt;code&gt;https://www.youtube.com/oembed/?url=https://youtu.be/Bk1jonYPFD4&lt;/code&gt; returns:&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-json&quot;&gt;{
  &amp;quot;title&amp;quot;: &amp;quot;Celebrating POW! (usepow.app)  \u00b7  A day in my life as a developer, founder and mom  \u00b7  March 2021&amp;quot;,
  &amp;quot;author_name&amp;quot;: &amp;quot;Queen Raae&amp;quot;,
  &amp;quot;author_url&amp;quot;: &amp;quot;https://www.youtube.com/c/QueenRaae&amp;quot;,
  &amp;quot;type&amp;quot;: &amp;quot;video&amp;quot;,
  &amp;quot;height&amp;quot;: 113,
  &amp;quot;width&amp;quot;: 200,
  &amp;quot;version&amp;quot;: &amp;quot;1.0&amp;quot;,
  &amp;quot;provider_name&amp;quot;: &amp;quot;YouTube&amp;quot;,
  &amp;quot;provider_url&amp;quot;: &amp;quot;https://www.youtube.com/&amp;quot;,
  &amp;quot;thumbnail_height&amp;quot;: 360,
  &amp;quot;thumbnail_width&amp;quot;: 480,
  &amp;quot;thumbnail_url&amp;quot;: &amp;quot;https://i.ytimg.com/vi/Bk1jonYPFD4/hqdefault.jpg&amp;quot;,
  &amp;quot;html&amp;quot;: &amp;quot;\u003ciframe width=\u0022200\u0022 height=\u0022113\u0022 src=\u0022https://www.youtube.com/embed/Bk1jonYPFD4?feature=oembed\u0022 frameborder=\u00220\u0022 allow=\u0022accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture\u0022 allowfullscreen\u003e\u003c/iframe\u003e&amp;quot;
}
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;Take note of &lt;code&gt;html&lt;/code&gt; on the YouTube response; it&apos;s all you need to embed a YouTube player to your site.&lt;/p&gt;
&lt;h2&gt;Sourcing nodes with oEmbed data&lt;/h2&gt;
&lt;p&gt;In Gatsby land, we can use oEmbed to ensure we have the correct embed snippet and/or the current title for our YouTube videos.&lt;/p&gt;
&lt;p&gt;We do so by using the &lt;code&gt;gatsby-node.js&lt;/code&gt; hook &lt;code&gt;sourceNodes&lt;/code&gt; where we create one content node per YouTube video and add the information from the oEmbed endpoint onto the node.&lt;/p&gt;
&lt;pre&gt;&lt;code class=&quot;language-js&quot;&gt;// gatsby-node.js
// Full code without error handling

const axios = require(&amp;quot;axios&amp;quot;);

const YOUTUBE_IDS = [&amp;quot;Bk1jonYPFD4&amp;quot;, &amp;quot;TzJfepDjpzM&amp;quot;];

const fetchEmbed = async (id) =&amp;gt; {
  const ytUrl = `https://youtu.be/${id}`;
  const { data } = await axios.get(&amp;quot;https://www.youtube.com/oembed&amp;quot;, {
    params: {
      url: ytUrl,
    },
  });
  return data;
};

const prepYouTubeNode = async (
  id,
  { actions: { createNode }, createNodeId, createContentDigest }
) =&amp;gt; {
  const embedData = await fetchEmbed(id);

  createNode({
    id: createNodeId(`you-tube-${id}`),
    oEmbed: embedData,
    internal: {
      type: `YouTube`,
      contentDigest: createContentDigest(embedData),
    },
  });
};

exports.sourceNodes = async (params) =&amp;gt; {
  await Promise.all(YOUTUBE_IDS.map((id) =&amp;gt; prepYouTubeNode(id, params)));
};
&lt;/code&gt;&lt;/pre&gt;
&lt;p&gt;&lt;strong&gt;Would you like to see this code refactored into a plugin?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
All the best,&lt;br&gt;
Queen Raae&lt;/p&gt;
&lt;p&gt; &lt;br&gt;
&lt;strong&gt;PS:&lt;/strong&gt; The Pirate Princess and I woke up in this &lt;a href=&quot;https://twitter.com/OlaHolstVea/status/1483819055584878593&quot;&gt;magical tree top hut&lt;/a&gt; today...&lt;/p&gt;
</content:encoded></item></channel></rss>