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-svg-contents

v0.7.0

Published

A plugin for 11ty to take an SVG and provide the contents of that file to a template

Downloads

2,440

Readme

eleventy-plugin-svg-contents

An Eleventy universal plugin to grab the contents of an SVG file to allow for embedding in your template with all the power of SVG.

Installation

Available on npm.

npm install eleventy-plugin-svg-contents --save

Open up your Eleventy config file (probably .eleventy.js) and add the plugin:

const svgContents = require("eleventy-plugin-svg-contents");
module.exports = function(eleventyConfig) {
  eleventyConfig.addPlugin(svgContents);
};

Usage

Base usage

In your (Nunjucks, Liquid or Handlebars) templates, use the following syntax to grab the contents from any SVG in your project path:

// nunjucks/liquid
{{ 'path/to/file.svg' | svgContents }}

// handlebars
{{{svgContents 'path/to/file.svg' }}}

Quick note: You may need to pass another filter after to have this render as html. In Nunjucks, you'll add | safe to the end.

Adding a class to your SVG

You can append the svg class with the class option.

// Nunjucks
{{ 'path/to/file.svg' | svgContents("extra-class-one extra-class-two") }}

// Liquid
{{ 'path/to/file.svg' | svgContents: "extra-class-one extra-class-two" }}

// Handlebars
{{{svgContents 'path/to/file.svg' "extra-class-one extra-class-two" }}}

Using other SVG elements

If you want to use an element selector other than SVG (or want to select a specific piece of an SVG) you can use an optional second argument to provide a selector for the element in your SVG file. Any selector strings will work (classes, ids, attr, element).

Due to limitations of Liquid and Handlebars, you'll need to have a placeholder string for the optional class name argument.

// Nunjucks
{{ 'path/to/file.svg' | svgContents("", "symbol") }}
{{ 'path/to/file.svg' | svgContents("add-class", "#byId") }}

// Liquid
{{ 'path/to/file.svg' | svgContents: "", "symbol" }}
{{ 'path/to/file.svg' | svgContents: "add-class", "#byId" }}

// Handlebars
{{{svgContents 'path/to/file.svg' "" "symbol" }}}
{{{svgContents 'path/to/file.svg' "add-class" "#byId" }}}

Filters

  • svgContents: Grabs the xml from an SVG and passes it to your template. Voila! Instant embedded SVG from a file!
  • Future Plan stripTitle: A filter to strip the <title> that often comes with SVGs and can cause havoc with SEO.