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-gen-favicons

v1.1.3

Published

Favicon generator plugin for eleventy

Downloads

6,977

Readme

Eleventy Favicon Generation

eleventy-plugin-gen-favicons

An Eleventy plugin to generate favicons based on the 2022 best practices.

Include as a {% favicons 'source-image.svg' %} in your template. On build, all relevant favicons will be generated, and HTML referencing the icons will be placed in your template.

Given a single square input icon file (preferably .svg), the following is generated:

  • /favicon.svg (only if a svg is provided)
  • /favicon.ico - 64x64/32x32/16x16 legacy icon
  • /apple-touch-icon.png - 180x180 Apple home screen icon including 20px (configurable) colored padding
  • /icon-192.png - Google home screen icon
  • /icon-512.png - Google loading screen
  • /manifest.webmanifest - Manifest linking the Google icons; can be customized with additional data

Installation

Available on npm.

npm install --save-dev eleventy-plugin-gen-favicons

In .eleventy.js (or your config file if differently named), use addPlugin:

// .eleventy.js
const faviconsPlugin = require("eleventy-plugin-gen-favicons");

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

NOTE If you already have module.exports, only copy the require and addPlugin lines, as with all other plugins.

The plugin accepts a few options (replace {} as necessary):

  • outputDir: default ./_site -- where to generate the icons; should match the eleventy output directory
  • manifestData: default {} -- additional data to include in the .webmanifest (e.g. {'name': 'My Website'})
  • generateManifest: default true -- set to false to disable manifest generation (if you're already generating a manifest separately)

Example:

  eleventyConfig.addPlugin(faviconsPlugin, {'outputDir': './generated_site', 'manifestData': {'name': 'My Website'}});

Usage

Include the favicons shortcode somewhere within <head> in your template (all languages except Handlebars are supported):

<head>
{% favicons 'my-source-image.svg', appleIconBgColor='#123' %}
</head>

NOTE Do not use multiple favicons shortcodes with different images or bg colors. Favicons are site-wide and this will result in undefined behavior. It is fine to conditionally set a favicon, as long as it's site-wide.

The shortcode accepts additional options:

  • appleIconBgColor: default 'white' -- the color to use for the Apple icon padding; accepts anything that can be parsed by color, such as 'white', '#fff', {r: 128, g: 0, b: 255, alpha: 0.75}, etc
  • appleIconPadding: default 20 -- the size of the Apple icon padding in px per side (must be less than 90px)
  • manifestData: default {} -- additional data to include in the .webmanifest (e.g. {'name': 'My Website'}); overrides the plugin setting of the same name
  • generateManifest: default true -- set to false to disable manifest generation (if you're already generating a manifest separately); overrides the plugin setting of the same name

Examples:

{% favicons 'favicon.svg' %}
{% favicons 'favicon.png' %}
{% favicons 'favicon.svg', appleIconBgColor='#000' %}
{% favicons 'favicon.svg', appleIconBgColor='black', manifestData={name:'My Website'} %}
{% favicons 'favicon.svg', appleIconBgColor='#f00', appleIconPadding=10, generateManifest=false %}

Example generated HTML:

<link rel="icon" href="/favicon.ico" sizes="any">
<link rel="icon" href="/favicon.svg" type="image/svg+xml">
<link rel="apple-touch-icon" href="/apple-touch-icon.png">
<link rel="manifest" href="/manifest.webmanifest">

Security

This package uses sharp and png-to-ico and at the time of publish shows no vulnerabilities with npm audit. It is fully tested and should not alter any files other than the favicons it generates.

More Favicons

This generates the "Six files that fit most needs" for favicons in 2022. For sites that require more icons, a custom solution based on the favicons package is recommended.

Contributing

PRs to the GitHub repo are welcome. Please make sure the tests pass.