by @raae
intro - what - why - journey - how - future plans
@raae
What
Why
Journey
How
Future plans
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
Learn more at oembed.com
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-images`,
options: {
maxWidth: 590
}
},
{
resolve: `@raae/gatsby-remark-oembed`
},
{
resolve: `gatsby-remark-responsive-iframe`,
options: {
wrapperStyle: `margin-bottom: 1.0725rem`
}
}
]
}
}@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
1.
Fetch the list of oembed providers
2.
For every markdown file look for oEmbed URLs, then for each URL send a request to the correct provider and swap it out with the HTML returned by the provider
3.
Do magic to get Twitter, Instagram, Flickr and Reddit to work
intro - what - why - journey - how - future plans
@raae
// gatsby-node.js
exports.onPreBootstrap = async ({ cache }) => {
const providers = await fetchOembedProviders();
return await cache.set("remark-oembed-providers", providers);
};intro - what - why - journey - how - future plans
@raae
// index.js
module.exports = async ({ markdownAST, cache }) => {
const providers = await cache.get("remark-oembed-providers");
const nodes = findPossibleOembedUrlNodes(markdownAST);
await Promise.all(
nodes.map(node => processNode(node, providers))
);
};
const processNode = async (node, providers) => {
const endpoint = getProviderEndpointForUrl(node.url, providers);
const oembedResponse = await fetchOembed(endpoint);
return tranformsUrlNodeToOembedNode(node, oembedResponse);
};intro - what - why - journey - how - future plans
@raae
// gatsby-ssr.js
const SCRIPTS = {
Twitter: "https://platform.twitter.com/widgets.js",
Instagram: "https://www.instagram.com/embed.js",
Flickr: "https://embedr.flickr.com/assets/client-code.js",
Reddit: "https://embed.redditmedia.com/widgets/platform.js"
};
const createScriptTag = (key, scriptSrc) => {
return React.createElement(
"script",
{ src: scriptSrc, key: `gatsby-plugin-oembed-${key.toLowerCase()}` },
null
);
};
exports.onRenderBody = ({ setPostBodyComponents }) => {
const scripts = Object.keys(SCRIPTS).map(key => createScriptTag(key, SCRIPTS[key]));
setPostBodyComponents(scripts);
};intro - what - why - journey - how - future plans
@raae
// gatsby-browser.js
const loadTwitter = () => {
twttr.widgets.load(document.getElementById("___gatsby"));
};
const processInstagram = () => {
instgrm.Embeds.process();
};
exports.onRouteUpdate = () => {
loadTwitter();
processInstagram();
};intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
Dev
Git repo directly as a local plugin
Test
Install a tag or branch directly from Github, not NPM
Prod
npm publish
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
intro - what - why - journey - how - future plans
@raae
Both open source and as a contractor
intro - what - why - journey - how - future plans
@raae
@raae on Twitter and Github
@raae.codes on Instagram