Giter VIP home page Giter VIP logo

eleventy-plugin-gen-favicons's Introduction

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.

eleventy-plugin-gen-favicons's People

Contributors

njaldwin avatar anantshri avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.