Gatsby Remark plugin to embed well known services by their URL.
Trying to embed well known services (like CodePen, CodeSandbox, GIPHY, Instagram, Lichess, Pinterest, Slides, SoundCloud, Spotify, Streamable, Testing Playground, Twitch, Twitter or YouTube) into your Gatsby website can be hard, since you have to know how this needs to be done for all of these different services.
gatsby-remark-embedder
tries to solve this problem for you by letting you just
copy-paste the link to the
gif/pen/pin/player/playground/post/sandbox/tweet/video you want to embed right
from within your browser onto a separate line (surrounded by empty lines) and
replace it with the proper embed-code.
This module is distributed via npm which is bundled with node and
should be installed as one of your project's dependencies
:
npm install gatsby-remark-embedder
or
yarn add gatsby-remark-embedder
This library has a required peerDependencies
listing for gatsby
and should be used as a plugin for
gatsby-transformer-remark
or
gatsby-plugin-mdx
.
Depending on the services you want to embed, you should
also install gatsby-plugin-instagram-embed
,
gatsby-plugin-pinterest
and/or
gatsby-plugin-twitter
.
// In your gatsby-config.js
module.exports = {
// Find the 'plugins' array
plugins: [
{
resolve: `gatsby-transformer-remark`,
options: {
plugins: [
{
resolve: `gatsby-remark-embedder`,
options: {
customTransformers: [
// Your custom transformers
],
services: {
// The service-specific options by the name of the service
},
},
},
// Other plugins here...
],
},
},
],
};
or
// In your gatsby-config.js
module.exports = {
// Find the 'plugins' array
plugins: [
{
resolve: `gatsby-plugin-mdx`,
options: {
gatsbyRemarkPlugins: [
{
resolve: `gatsby-remark-embedder`,
options: {
customTransformers: [
// Your custom transformers
],
services: {
// The service-specific options by the name of the service
},
},
},
// Other plugins here...
],
},
},
],
};
https://codepen.io/team/codepen/pen/PNaGbb
https://codesandbox.io/s/ynn88nx9x?view=split
https://giphy.com/gifs/howtogiphygifs-how-to-XatG8bioEwwVO
The returned HTML snippet from the Instagram transformer will only be
automatically recognized as an embedded post when Instagram's embed JavaScript
is included on the page.
Since the Instagram transformer doesn't include this JavaScript (because we
don't want to include it multiple times on a page when having multiple embeds),
you have to include it yourself. The recommended way of including it is by using
gatsby-plugin-instagram-embed
.
https://instagram.com/p/B60jPE6J8U-
```
All options should go under the Instagram
namespace.
name | Type | Required | Default | Description |
---|---|---|---|---|
accessToken | string |
β | An App Access Token (recommended) or Client Access Token |
To get an App Access Token (recommended) or Client Access Token for the Instagram embed, check out the Instagram oEmbed access token docs and requirements.
The safest way to enter your accessToken
is to set is as an environment
variable.
https://lichess.org/MPJcy1JW
The returned HTML snippet from the Pinterest transformer will only be
automatically recognized as an embedded pin when Pinterest's embed JavaScript is
included on the page.
Since the Pinterest transformer doesn't include this JavaScript (because we
don't want to include it multiple times on a page when having multiple embeds),
you have to include it yourself. The recommended way of including it is by using
gatsby-plugin-pinterest
.
https://pinterest.com/pin/99360735500167749
https://slides.com/kentcdodds/oss-we-want
https://soundcloud.com/clemenswenners/africa
https://open.spotify.com/track/0It2bnTdLl2vyymzOkBI3L
https://streamable.com/moo
https://testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a
Twitch embeds can only be embedded on HTTPS websites. Check out the Gatsby docs for setting this up when developing locally.
https://twitch.tv/videos/546761743
All options should go under the Twitch
namespace.
name | Type | Required | Default | Description |
---|---|---|---|---|
parent | string / string[] |
β | Domain(s) that will be embedding Twitch. You must have one parent key for each domain your site uses. |
You could either put in (a) hardcoded value(s) or you could use environment variables that are available during the build process.
Netlify has the URL
, DEPLOY_URL
and DEPLOY_PRIME_URL
environment
variables. Take a look at the Netlify docs
for more info.
Vercel has the VERCEL_URL
environment variable. Take a look at the Vercel
docs for more info.
The returned HTML snippet from the Twitter transformer will only be
automatically recognized as an Embedded Tweet when
Twitter's widget JavaScript is included on the
page.
Since the Twitter transformer doesn't include this JavaScript (because we don't
want to include it multiple times on a page when having multiple embeds), you
have to include it yourself. The recommended way of including it is by using
gatsby-plugin-twitter
.
https://twitter.com/MichaelDeBoey93/status/1152991421789548546
https://twitter.com/i/moments/994601867987619840
https://twitter.com/wesbos/timelines/1189618481672667136
π₯ Design Tips π₯ Hot Tips from Wes Bos - Curated tweets by wesbos ```Happy to announce I just published the first gatsby-remark-embedder πππ
β MichaΓ«l De Boey (@MichaelDeBoey93) July 21, 2019
This first version is an extract of @kentcdodds' personal website remark-embedder plugin, but I'm planning on adding extra services then @codesandbox, @Twitter & @YouTube too. https://t.co/M4PA9aFZdG
The YouTube transformer (currently) only supports videos in the following formats:
https://youtube.com/watch?v=dQw4w9WgXcQ
)https://youtu.be/dQw4w9WgXcQ
)https://youtu.be/dQw4w9WgXcQ
The plugin allows you to pass an array of custom transformers that will be executed additionally to the default ones.
Each transformer should be an object which has the following properties:
getHTML(url, options)
The getHTML
method is executed when the given URL has been matched to
transform. It should return the transformed HTML.
This asynchronous function receives the URL to transform together with an
options object to take into account when transforming.
name
The name
is the value that needs to be used as a key in the
services
plugin option. The value for this key will be provided
as the second argument to getHTML
.
shouldTransform(url)
The shouldTransform
method should check if the given URL matches the one
intended to transform. It should return a boolean value.
// some-site-transformer.js
const getHTML = (url) => `<iframe src="https://github.com/MichaelDeBoey/gatsby-remark-embedder/raw/main/${url}"></iframe>`;
const name = 'someSite';
const regex = /^https?:\/\/some-site\.com\//;
const shouldTransform = (url) => regex.test(url);
module.exports = { getHTML, name, shouldTransform };
The plugin also allows you to pass an object which keys that represent the name of the service to transform and the value that's an object with options for that specific service.
This whole plugin was extracted out of Kent C. Dodds' personal website.
The intention is to make this available to be used independently.
Looking to contribute? Look for the Good First Issue label.
Please file an issue for bugs, missing documentation, or unexpected behavior.
Please file an issue to suggest new features. Vote on feature requests by adding a π. This helps maintainers prioritize what to work on.
Thanks goes to these people (emoji key):
This project follows the all-contributors specification. Contributions of any kind welcome!
MIT