eleventy-plugin-vimeo-embed
This Eleventy plugin automatically embeds responsive Vimeo videos from URLs in Markdown files.
- ⚡️ Installation
- 🛠 Usage
- ⚙️ Settings
⚠️ Notes and caveats
⚡️ Installation
In your Eleventy project, install the plugin through npm:
$ npm i eleventy-plugin-vimeo-embed
Then add it to your Eleventy config file:
const embedVimeo = require("eleventy-plugin-vimeo-embed");
module.exports = function(eleventyConfig) {
eleventyConfig.addPlugin(embedVimeo);
};
🛠 Usage
To embed a Vimeo video into any Markdown page, paste its URL into a new line. The URL should be the only thing on that line.
Markdown file example:
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nam vehicula, elit vel condimentum porta, purus.
https://vimeo.com/347565673
Maecenas non velit nibh. Aenean eu justo et odio commodo ornare. In scelerisque sapien at.
Result:
⚙️ Settings
You can configure the plugin to change its behavior by passing an options object to the addPlugin
function:
eleventyConfig.addPlugin(embedVimeo, {
// edit options here
});
Plugin default options
Edit any of the default values in this options object to override the plugin behavior. These are the default settings, which will apply to all embed instances. Currently there’s no way to configure individual embeds.
{
// Default “allowfullscreen” boolean attribute that gets applied to the embed <iframe>.
// Change to false to disable fullscreen.
allowFullscreen: true,
// Default “dnt” (“do-not-track”) boolean attribute that gets applied to the embed URL.
// Change to false to allow cookies and other tracking technology.
dnt: true,
// Default class that gets applied to the wrapper <div>.
// Substitute your preferred string to target embeds with CSS.
embedClass: 'eleventy-plugin-vimeo-embed'
});
Supported URL patterns
The plugin supports common Vimeo URL variants as well. These should also work in your Markdown files.:
<!-- No protocol: -->
vimeo.com/347565673
www.vimeo.com/347565673
<!-- With or without HTTPS: -->
http://vimeo.com/347565673
https://vimeo.com/347565673
<!-- With or without 'www': -->
https://www.vimeo.com/347565673
https://vimeo.com/347565673
<!-- URLs with extra parameters or fragments: -->
https://vimeo.com/347565673?autoplay=1
https://vimeo.com/347565673#t30s
If you run across a URL pattern that you think should work, but doesn’t, please file an issue!
⚠️ Notes and caveats
- This plugin is deliberately designed only to embed videos when the URL is on its own line, and not inline with other text.
- To do this, it uses a regular expression to recognize Vimeo video URLs. Currently these are the limitations on what it can recognize in a Markdown parser’s HTML output:
- The URL must be wrapped in a paragraph tag:
<p>
- It may also be wrapped in an anchor tag, (inside the paragraph):
<a>
- The URL string may have whitespace around it
- The URL must be wrapped in a paragraph tag:
- I’ve tried to accommodate common variants, but there are conceivably valid Vimeo URLs that wouldn’t get recognized. Please file an issue if you run into an edge case!
- This plugin uses transforms, so it alters Eleventy’s HTML output as it’s generated. It doesn’t alter the source Markdown.
- The embedded video is responsive, using the intrinsic aspect ratio method. It will expand to fill whatever horizontal space is available.
- The embed dimensions are currently hard-coded to a 16:9 aspect ratio.