npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

eleventy-plugin-embedded-demos

v1.1.0

Published

A plugin for eleventy that allows you to have embedded demos using HTML, CSS and JavaScript, as well as having the code from those demos displayed in the page.

Downloads

1

Readme

eleventy-plugin-embedded-demos

A plugin for eleventy that allows you to have embedded demos using HTML, CSS and JavaScript, as well as having the code from those demos displayed in the page.

Install

Available on npm.

npm install --save-dev eleventy-plugin-embedded-demos

Usage

Loading and configuring

In your Eleventy config file (probably .eleventy.js), load the plugin module and use .addPlugin to add it to Eleventy. Like this:

const demos = require("eleventy-plugin-embedded-demos");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(demos);
};

REMEMBER: You’re only allowed one module.exports in your configuration file, so make sure you only copy the require and the .addPlugin lines above!

You can also pass an object to the .addPlugin call as the second parameter to configure the plugin. Like this:

const demos = require("eleventy-plugin-embedded-demos");

module.exports = function (eleventyConfig) {
  eleventyConfig.addPlugin(demos, {
    path: "./src/demos",
    filenames: {
      javascript: "script.js",
    },
  });
};

Any options you pass will be used to override the equivalent defaults.

Demo layout

You'll need a layout for your demo files so that all the various parts of the demo can be included.

The plugin adds 2 shortcodes to enable this:

  • demoCss: inlines the CSS for that demo into the page
  • demoJS: inlines the JS for that demo into the page

An example of a minimal Nunjucks layout for demo files would be this:

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>{{ title }}</title>
    {% demoCss %}
  </head>
  <body>
    <main id="demo-content" title="{{ title }}">
      {{ content | safe }}
    </main>
    {% demoJS %}
  </body>
</html>

You'll then need to specify that your demo pages should use this layout, either in your template front-matter or in a directory data file

Creating a demo

To create a demo, create a folder within your demos folder (default: ./demos). This can also be nested if you want to group multiple demos.

The only required file for a demo is a page written in any template language supported by Eleventy. The plugin looks for index.* by default.

You can optionally have a CSS file (default name styles.css) and a JavaScript file (default name main.js).

You can overide the CSS and JavaScript file names for a particular demo in your main demo file front-matter, as keys under a filenames key. For example:

---
title: "Basic clip-path demo"
filenames:
  javascript: "script.js"
---

Embedding demos in pages

You can embed a demo in your page using the embeddedDemo shortcode and passing it the path within your demos folder that the plugin should look for the files in.

For example, if we had a demo that lived at ./demos/clip-path/basic, we'd call the shortcode in Nunjucks like this:

{% embeddedDemo "clip-path/basic" %}

Configuration options

Below are all the options that can be passed to the plugin:

path

./demos

The path to your demos folder, relative to the root of your Eleventy project.

Note: This must be inside your Eleventy input directory

prettier

true

parsers

{
  html: "html",
  css: "css",
  javascript: "babel",
}

filenames

{
  html: "index.*",
  css: "styles.css",
  javascript: "main.js",
}

An object keyed by file type with the file name to look for.

Note: Only the html value can be a glob

displayNames

{
  html: "HTML",
  css: "CSS",
  javascript: "JavaScript",
  result: "Result",
}

open

{
  html: false,
  css: false,
  javascript: false,
  result: true,
}

Defaults

All of the defaults are exposed on the defaults property of the module, so they can be used in your config if necessary.