Gatsby Remark plugin to embed well known services by their URL.
npm install gatsby-remark-embedder
Gatsby Remark plugin to embed well known services by their URL.
---
[![Build Status][build-badge]][build]
[![Code Coverage][coverage-badge]][coverage]
[![version][version-badge]][package]
[![downloads][downloads-badge]][npmtrends]
[![MIT License][license-badge]][license]
[![All Contributors][all-contributors-badge]](#contributors-)
[![PRs Welcome][prs-badge]][prs]
[![Code of Conduct][coc-badge]][coc]
Trying to embed well known services (like [CodePen][codepen],
[CodeSandbox][codesandbox], [GIPHY][giphy], [Instagram][instagram],
[Lichess][lichess], [Pinterest][pinterest], [Slides][slides],
[SoundCloud][soundcloud], [Spotify][spotify], [Streamable][streamable], [Testing
Playground][testing-playground], [Twitch][twitch], [Twitter][twitter] or
[YouTube][youtube]) into your [Gatsby][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.
- Installation
- Usage
- Supported services
- CodePen
- CodeSandbox
- GIPHY
- Instagram
- Lichess
- Pinterest
- Slides
- SoundCloud
- Spotify
- Streamable
- Testing Playground
- Twitch
- Twitter
- YouTube
- Options
- customTransformers
- services
- Inspiration
- Issues
- π Bugs
- π‘ Feature Requests
- Contributors β¨
- LICENSE
This module is distributed via [npm][npm] which is bundled with [node][node] and
should be installed as one of your project's dependencies:
``sh`
npm install gatsby-remark-embedder
or
`sh`
yarn add gatsby-remark-embedder
This library has a required peerDependencies listing for [gatsby][gatsby]gatsby-transformer-remark
and should be used as a plugin for
[][gatsby-transformer-remark] orgatsby-plugin-mdx
[][gatsby-plugin-mdx]. gatsby-plugin-instagram-embed
Depending on the services you want to embed, you should
also install [][gatsby-plugin-instagram-embed],gatsby-plugin-pinterest
[][gatsby-plugin-pinterest] and/orgatsby-plugin-twitter
[][gatsby-plugin-twitter].
`js
// In your gatsby-config.js
module.exports = {
// Find the 'plugins' array
plugins: [
{
resolve: gatsby-transformer-remark,gatsby-remark-embedder
options: {
plugins: [
{
resolve: ,
options: {
customTransformers: [
// Your custom transformers
],
services: {
// The service-specific options by the name of the service
},
},
},
// Other plugins here...
],
},
},
],
};
`
or
`js
// In your gatsby-config.js
module.exports = {
// Find the 'plugins' array
plugins: [
{
resolve: gatsby-plugin-mdx,gatsby-remark-embedder
options: {
gatsbyRemarkPlugins: [
{
resolve: ,
options: {
customTransformers: [
// Your custom transformers
],
services: {
// The service-specific options by the name of the service
},
},
},
// Other plugins here...
],
},
},
],
};
`
#### Usage
`md`
https://codepen.io/team/codepen/pen/PNaGbb
Result
`html`
src="https://codepen.io/team/codepen/embed/preview/PNaGbb"
style="width:100%; height:300px;"
>
#### Usage
`md`
https://codesandbox.io/s/ynn88nx9x?view=split
Result
`html`
src="https://codesandbox.io/embed/ynn88nx9x?view=split"
style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;"
allow="geolocation; microphone; camera; midi; vr; accelerometer; gyroscope; payment; ambient-light-sensor; encrypted-media; usb"
sandbox="allow-modals allow-forms allow-popups allow-scripts allow-same-origin"
>
#### Usage
`md`
https://giphy.com/gifs/howtogiphygifs-how-to-XatG8bioEwwVO
Result
`html`
src="https://giphy.com/embed/XatG8bioEwwVO"
width="100%"
height="100%"
style="position:absolute"
frameborder="0"
class="giphy-embed"
allowfullscreen
>
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][gatsby-plugin-instagram-embed].
#### Usage
`md`
https://instagram.com/p/B60jPE6J8U-
Result
`html
class="instagram-media"
data-instgrm-captioned
data-instgrm-permalink="https://www.instagram.com/p/B60jPE6J8U-/?utm_source=ig_embed&utm_campaign=loading"
data-instgrm-version="12"
style="background:#FFF; border:0; border-radius:3px; box-shadow:0 0 1px 0 rgba(0,0,0,0.5),0 1px 10px 0 rgba(0,0,0,0.15); margin: 1px; max-width:540px; min-width:326px; padding:0; width:99.375%; width:-webkit-calc(100% - 2px); width:calc(100% - 2px);"
>
href="https://www.instagram.com/p/B60jPE6J8U-/?utm_source=ig_embed&utm_campaign=loading"
style="background:#FFFFFF; line-height:0; padding:0 0; text-align:center; text-decoration:none; width:100%;"
target="_blank"
>
style="background-color: #F4F4F4; border-radius: 50%; flex-grow: 0; height: 40px; margin-right: 14px; width: 40px;"
>
style="display: flex; flex-direction: column; flex-grow: 1; justify-content: center;"
>
style="background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; margin-bottom: 6px; width: 100px;"
>
style="background-color: #F4F4F4; border-radius: 4px; flex-grow: 0; height: 14px; width: 60px;"
>
href="https://www.instagram.com/p/B60jPE6J8U-/?utm_source=ig_embed&utm_campaign=loading"
style="color:#000; font-family:Arial,sans-serif; font-size:14px; font-style:normal; font-weight:normal; line-height:17px; text-decoration:none; word-wrap:break-word;"
target="_blank"
>Good morning New York! π½ #newyork #nyc #brotrip #newyear #2020 #city
#bluesky #clearsky #timessquare #nycitylife #nycityworld #urban
#manhattan #travel #cold #winter #citytrip #lastday #streetview
#citythatneversleeps #bucketlist #buildings #skyscraper #midtown >
#### Options
All options should go under the
Instagram namespace.| name | Type | Required | Default | Description |
| ----------- | -------- | -------- | ------- | -------------------------------------------------------- |
| accessToken |
string | β
| | An App Access Token (recommended) or Client Access Token |##### accessToken
To get an App Access Token (recommended) or Client Access Token for the
Instagram embed, check out the [Instagram oEmbed access token
docs][instagram-oembed-access-token-docs] and
[requirements][instagram-oembed-requirements-docs].
The safest way to enter your
accessToken is to set is as an [environment
variable][gatsby-environment-variables-docs].
Example
`js
const GatsbyRemarkEmbedderOptions = {
services: {
Instagram: {
accessToken: process.env.INSTAGRAM_ACCESS_TOKEN,
},
},
};
`$3
#### Usage
`md
https://lichess.org/MPJcy1JW
`
Result
`html
src="https://lichess.org/embed/MPJcy1JW"
width="600"
height="397"
frameborder="0"
>
`$3
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][gatsby-plugin-pinterest].#### Usage
`md
https://pinterest.com/pin/99360735500167749
`
Result
`html
data-pin-do="embedPin"
href="https://pinterest.com/pin/99360735500167749"
>
`$3
#### Usage
`md
https://slides.com/kentcdodds/oss-we-want
`
Result
`html
src="https://slides.com/kentcdodds/oss-we-want/embed"
width="576"
height="420"
scrolling="no"
frameborder="0"
webkitallowfullscreen
mozallowfullscreen
allowfullscreen
>
`$3
#### Usage
`md
https://soundcloud.com/clemenswenners/africa
`
Result
`html
width="100%"
height="300"
scrolling="no"
frameborder="no"
src=https://w.soundcloud.com/player?url=https://soundcloud.com/clemenswenners/africa&color=ff5500&auto_play=false&hide_related=true&show_comments=true&show_user=true&show_reposts=false&show_teaser=false&visual=true
>
`$3
#### Usage
`md
https://open.spotify.com/track/0It2bnTdLl2vyymzOkBI3L
`
Result
`html
src="https://open.spotify.com/embed/track/0It2bnTdLl2vyymzOkBI3L"
width="100%"
height="380"
frameborder="0"
allowtransparency="true"
allow="encrypted-media"
>
`$3
#### Usage
`md
https://streamable.com/moo
`
Result
`html
class="streamable-embed"
src="https://streamable.com/o/moo"
frameborder="0"
scrolling="no"
width="1920"
height="1080"
allowfullscreen
>
`$3
#### Usage
`md
https://testing-playground.com/gist/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a
`
Result
`html
src="https://testing-playground.com/embed/fb336c386145b235372a0f57d5c58205/6d13e4ee508301c8b42f9d2cc8584e70bb05fb4a?panes=query,preview"
height="450"
width="100%"
scrolling="no"
frameborder="0"
allowTransparency="true"
style="overflow: hidden; display: block; width: 100%"
>
`$3
Twitch embeds can only be embedded on HTTPS websites. Check out [the Gatsby
docs][gatsby-https-docs] for setting this up when developing locally.
#### Usage
`md
https://twitch.tv/videos/546761743
`
Result
`html
src="https://player.twitch.tv/?video=546761743"
height="300"
width="100%"
frameborder="0"
scrolling="no"
allowfullscreen
>
`#### Options
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. |##### parent
You could either put in (a) hardcoded value(s) _or_ you could use environment
variables that are available during the build process.
###### Netlify
Netlify has the
URL, DEPLOY_URL and DEPLOY_PRIME_URL environment
variables. Take a look at [the Netlify docs][netlify-environment-variables-docs]
for more info.
Example
`js
const GatsbyRemarkEmbedderOptions = {
services: {
Twitch: {
parent: [
process.env.URL,
process.env.DEPLOY_URL,
process.env.DEPLOY_PRIME_URL, // Other domains here...
],
},
},
};
`###### Vercel
Vercel has the
VERCEL_URL environment variable. Take a look at [the Vercel
docs][vercel-environment-variables-docs] for more info.
Example
`js
const GatsbyRemarkEmbedderOptions = {
services: {
Twitch: {
parent: [
process.env.VERCEL_URL, // Other domains here...
],
},
},
};
`$3
The returned HTML snippet from the Twitter transformer will only be
automatically recognized as an [Embedded Tweet][embedded-tweet-docs] when
[Twitter's widget JavaScript][twitter-widget-javascript-docs] 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][gatsby-plugin-twitter].#### Usage
`md
https://twitter.com/MichaelDeBoey93/status/1152991421789548546https://twitter.com/i/moments/994601867987619840
https://twitter.com/wesbos/timelines/1189618481672667136
`
Result
`html
Happy to announce I just published the first gatsby-remark-embedder πππ
This first version is an extract of
@kentcdodds' personal website
remark-embedder plugin, but I'm planning on adding extra services then
@codesandbox, href="https://twitter.com/Twitter"
>
@Twitter
& @YouTube too.
https://t.co/M4PA9aFZdG
β MichaΓ«l De Boey (@MichaelDeBoey93)
July 21, 2019
class="twitter-moment"
href="https://twitter.com/i/moments/994601867987619840"
>
π₯ Design Tips
class="twitter-timeline"
href="https://twitter.com/wesbos/timelines/1189618481672667136"
>
π₯ Hot Tips from Wes Bos - Curated tweets by wesbos
`$3
The YouTube transformer (currently) only supports videos in the following
formats:
- Full url (
https://youtube.com/watch?v=dQw4w9WgXcQ)
- Short url (https://youtu.be/dQw4w9WgXcQ)#### Usage
`md
https://youtu.be/dQw4w9WgXcQ
`
Result
`html
width="100%"
height="315"
src="https://www.youtube-nocookie.com/embed/dQw4w9WgXcQ?rel=0"
frameborder="0"
allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture"
allowfullscreen
>
`Options
$3
The plugin allows you to pass an array of custom transformers that will be
executed additionally to the default ones.
#### Properties
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.#####
nameThe
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.#### Example transformer
`js
// some-site-transformer.js
const getHTML = (url) => ;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][kentcdodds.com-repo].
The intention is to make this available to be used independently.
_Looking to contribute? Look for the [Good First Issue][good-first-issue]
label._
Please file an issue for bugs, missing documentation, or unexpected behavior.
[See Bugs][bugs]
Please file an issue to suggest new features. Vote on feature requests by adding
a π. This helps maintainers prioritize what to work on.
[See Feature Requests][requests]
Thanks goes to these people ([emoji key][emojis]):
This project follows the [all-contributors][all-contributors] specification.
Contributions of any kind welcome!
MIT
[npm]: https://www.npmjs.com
[node]: https://nodejs.org
[build-badge]: https://img.shields.io/github/workflow/status/MichaelDeBoey/gatsby-remark-embedder/validate?logo=github&style=flat-square
[build]: https://github.com/MichaelDeBoey/gatsby-remark-embedder/actions?query=workflow%3Avalidate
[coverage-badge]: https://img.shields.io/codecov/c/github/MichaelDeBoey/gatsby-remark-embedder.svg?style=flat-square
[coverage]: https://codecov.io/github/MichaelDeBoey/gatsby-remark-embedder
[version-badge]: https://img.shields.io/npm/v/gatsby-remark-embedder.svg?style=flat-square
[package]: https://www.npmjs.com/package/gatsby-remark-embedder
[downloads-badge]: https://img.shields.io/npm/dm/gatsby-remark-embedder.svg?style=flat-square
[npmtrends]: https://www.npmtrends.com/gatsby-remark-embedder
[license-badge]: https://img.shields.io/npm/l/gatsby-remark-embedder.svg?style=flat-square
[license]: https://github.com/MichaelDeBoey/gatsby-remark-embedder/blob/main/LICENSE
[prs-badge]: https://img.shields.io/badge/PRs-welcome-brightgreen.svg?style=flat-square
[prs]: https://makeapullrequest.com
[coc-badge]: https://img.shields.io/badge/code%20of-conduct-ff69b4.svg?style=flat-square
[coc]: https://github.com/MichaelDeBoey/gatsby-remark-embedder/blob/main/CODE_OF_CONDUCT.md
[emojis]: https://allcontributors.org/docs/en/emoji-key
[all-contributors]: https://github.com/all-contributors/all-contributors
[all-contributors-badge]: https://img.shields.io/github/all-contributors/MichaelDeBoey/gatsby-remark-embedder?color=orange&style=flat-square
[bugs]: https://github.com/MichaelDeBoey/gatsby-remark-embedder/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Acreated-desc+label%3Abug
[requests]: https://github.com/MichaelDeBoey/gatsby-remark-embedder/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3Aenhancement
[good-first-issue]: https://github.com/MichaelDeBoey/gatsby-remark-embedder/issues?utf8=%E2%9C%93&q=is%3Aissue+is%3Aopen+sort%3Areactions-%2B1-desc+label%3A%22good+first+issue%22
[codepen]: https://codepen.io
[codesandbox]: https://codesandbox.io
[embedded-tweet-docs]: https://developer.twitter.com/web/embedded-tweets
[gatsby]: https://github.com/gatsbyjs/gatsby
[gatsby-environment-variables-docs]: https://www.gatsbyjs.com/docs/environment-variables
[gatsby-https-docs]: https://gatsbyjs.org/docs/local-https
[gatsby-plugin-instagram-embed]: https://github.com/MichaelDeBoey/gatsby-plugin-instagram-embed
[gatsby-plugin-mdx]: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-mdx
[gatsby-plugin-pinterest]: https://github.com/robinmetral/gatsby-plugin-pinterest
[gatsby-plugin-twitter]: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-plugin-twitter
[gatsby-transformer-remark]: https://github.com/gatsbyjs/gatsby/tree/master/packages/gatsby-transformer-remark
[giphy]: https://giphy.com
[instagram]: https://instagram.com
[instagram-oembed-access-token-docs]: https://developers.facebook.com/docs/instagram/oembed#access-tokens
[instagram-oembed-requirements-docs]: https://developers.facebook.com/docs/instagram/oembed#requirements
[kentcdodds.com-repo]: https://github.com/kentcdodds/kentcdodds.com
[lichess]: https://lichess.org
[netlify-environment-variables-docs]: https://docs.netlify.com/configure-builds/environment-variables/#deploy-urls-and-metadata
[pinterest]: https://pinterest.com
[slides]: https://slides.com
[soundcloud]: https://soundcloud.com
[spotify]: https://spotify.com
[streamable]: https://streamable.com
[testing-playground]: https://testing-playground.com
[twitch]: https://twitch.tv
[twitter]: https://twitter.com
[twitter-widget-javascript-docs]: https://developer.twitter.com/en/docs/twitter-for-websites/javascript-api/overview
[vercel-environment-variables-docs]: https://vercel.com/docs/v2/build-step?query=Build#system-environment-variables
[youtube]: https://youtube.com