posthtml / posthtml-inline-favicon

PostHTML plugin to inline favicons
MIT License
2 stars 0 forks source link
data-uri favicon inline posthtml posthtml-plugin

posthtml-inline-favicon

NPM

posthtml-inline-favicon is a PostHTML plugin to inline favicons.

Before:

<head>
  <link rel="icon" href="https://github.com/posthtml/posthtml-inline-favicon/blob/master/favicon.ico" />
</head>

After:

<head>
  <link rel="icon" type="image/png" href="https://github.com/posthtml/posthtml-inline-favicon/blob/master/data:image/png;base64,..." />
</head>

Install

# npm
npm i -D posthtml-inline-favicon

# pnpm
pnpm add -D posthtml-inline-favicon

# Yarn
yarn add -D posthtml-inline-favicon

Usage

const fs = require("fs");
const posthtml = require("posthtml");
const { inlineFavicon } = require("posthtml-inline-favicon");

const html = fs.readFileSync("./index.html");

posthtml()
  .use(inlineFavicon())
  .process(html)
  .then((result) => fs.writeFileSync("./after.html", result.html));

Options

By default, the plugin assumes that the file to process is in the same directory as the posthtml script. If not, specify the relative path to the html file in the options:

const fs = require("fs");
const posthtml = require("posthtml");
const { inlineFavicon } = require("posthtml-inline-favicon");

const html = fs.readFileSync("./public/index.html");

posthtml()
  .use(inlineFavicon({ path: "public" }))
  .process(html)
  .then((result) => fs.writeFileSync("./after.html", result.html));

Example

Contributing

See the PostHTML Guidelines.

Changelog

License

MIT