• Stars
    star
    327
  • Rank 127,929 (Top 3 %)
  • Language
    JavaScript
  • License
    MIT License
  • Created over 8 years ago
  • Updated almost 6 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A Bash script to build a SVG sprite from a folder of SVG files (typically icons).

spritesh

A Node.js script to build a SVG sprite from a folder of SVG files (typically icons).

Install

npm install spritesh -g
gem install spritesh

Or you know, you can also just copy the script.

Usage

Usage: spritesh [options]
Script to build a SVG sprite from a folder of SVG files.
Options:
  -h, --help             Shows this help
  -q, --quiet            Disables informative output
  -i, --input [dir]      Specifies input dir (current dir by default)
  -o, --output [file]    Specifies output file ("./sprite.svg" by default)
  -v, --viewbox [str]    Specifies viewBox attribute (parsed by default)
  -p, --prefix [str]     Specifies prefix for id attribute (none by default)

Examples

  1. Generate sprite.svg from SVG files in current folder (all defaults).

    spritesh
  2. Generate sprite.svg from SVG files in assets/images/icons.

    spritesh --input assets/images/icons
  3. Generate _includes/icons.svg from SVG files in current folder.

    spritesh --output _includes/icons.svg
  4. Generate sprite.svg from SVG files in current folder with a view box of 0 0 16 16.

    spritesh --viewbox "0 0 16 16"
  5. Generate sprite.svg from SVG files in current folder with id attributes prefixed with i_.

    spritesh --prefix i_

SVG Optimisation

spritesh is a teeny tiny Bash script that takes care of SVG files concatenation; it does not perform any SVG optimisation. I recommend you add svgo (or similar tool) to your workflow to have an optimised and efficient SVG sprite.

An example that starts with improving the SVG files, then build a sprite could be:

svgo -f assets/images/icons && spritesh -i assets/images/icons

Accessibility

spritesh doesn’t help with SVG icons accessibility in itself. It is the responsibility of the developer (a.k.a you) to make sure the original icon files are including the relevant accessibility bits: a <title> tag with and id attribute.

For instance, a logo.svg icon could look like this:

<svg …>
  <title id="icon-brand-name">Your company/product name here</title>
  <!-- SVG content -->
</svg>

Which will generate this sprite (where icon- is the --prefix option):

<!-- sprite -->
<svg xmlns="http://www.w3.org/2000/svg" style="display: none;">
  <symbol id="icon-brand" viewBox="0 0 20 20">
    <svg …>
      <title id="icon-brand-name">Your company/product name here</title>
      <!-- SVG Content -->
    </svg>
  </symbol>
  <!-- Other symbols -->
</svg>

Later on, when using the sprite through <svg>/<use>, add an aria-labelledby attribute to the <svg> element referencing the relevant <title> id.

<svg class="logo" aria-labelledby="icon-brand-name">
  <use xlink:href="#icon-brand"></use>
</svg>

More Repositories

1

a11y-toggle

A tiny script for accessible content toggles.
HTML
304
star
2

iframify

Replace a node with an iframe version of itself
JavaScript
212
star
3

minwidth-relocate

JavaScript
125
star
4

outline-audit

A script to test the heading outline of a document
HTML
114
star
5

faster-react-tabs

JavaScript
48
star
6

gatsby-source-shopify-storefront

Gatsby source plugin for building websites using product data from the Shopify Storefront API
JavaScript
31
star
7

craft3-heroku-starterkit

This is a starter kit for Craft3 which helps you to install the CMS on Heroku
JavaScript
18
star
8

transync

A npm module to synchronise translation files.
JavaScript
10
star
9

nanoc-html5-template

A nanoc template using Sass, Haml and Compass Html5 Boilerplate
JavaScript
10
star
10

espi-devblog

Edenspiekermann Developer Blog
HTML
9
star
11

craft-jwt-auth

Enable authentication to Craft through the use of Javascript Web Tokens (JWT)
PHP
5
star
12

espi-eslint-config

ESLint configuration
JavaScript
3
star
13

espi-dni

PostBot for DNI Project
Elixir
3
star
14

themer

A Tumblr theme parser for local development.
PHP
3
star
15

edenspiekermann-storybook-starter

Boilerplate repo for React-based component libraries
CSS
2
star
16

bright

JavaScript
2
star
17

site-status

Keep track of website development status
Ruby
2
star
18

static-importer

JavaScript
1
star
19

card-builder-docs

Docs to assist with the implementation of Card Builder (http://cards.edenspiekermann.com/)
1
star
20

signals

Signals from content
JavaScript
1
star
21

react-project-examples

Example projects to test styleguide usage
JavaScript
1
star
22

kupong_integration

Ruby
1
star