metalsmith-html-glob
TypeScript icon, indicating that this package has built-in type declarations

2.0.1 • Public • Published

metalsmith-html-glob

npm: version npm: downloads

Snyk: vulnerabilities codecov: coverage license

A Metalsmith plugin to apply glob patterns within HTML.

This plugin works by expanding glob patterns in hyperlinks and resource links such as <script src="**/*.js"></script>. See below for a complete example.

Installation

npm install --save metalsmith-html-glob

JavaScript Usage

const Metalsmith = require('metalsmith');
const glob       = require('metalsmith-html-glob');

Metalsmith(__dirname)
    .use(glob({
        // options here
    }))
    .build((err) => {
        if (err) {
            throw err;
        }
    });

Options

html (optional)

Type: string Default: "**/*.html"

A micromatch glob pattern to find HTML files.

tags (optional)

Type: object Default:

{
    "a": "href",
    "img": ["src", "data-src"],
    "link": "href",
    "script": "src"
}

An object of what attributes in what tags to process glob patterns for.

Example HTML

Example Input

Given a file tree:

.
├── index.html
└── static
    ├── css
    │   ├── bootstrap.min.css
    │   └── fontawesome.all.min.css
    └── js
        ├── bootstrap.min.js
        └── popper.js

And index.html:

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="**/*.css">
    </head>
    <body>
        <script src="**/*.js"></script>
    </body>
</html>

Example Output

This plugin will change the contents of index.html to:

<!DOCTYPE html>
<html lang="en">
    <head>
        <link rel="stylesheet" href="static/css/bootstrap.min.css">
        <link rel="stylesheet" href="static/css/fontawesome.all.min.css">
    </head>
    <body>
        <script src="static/js/bootstrap.min.js"></script>
        <script src="static/js/popper.js"></script>
    </body>
</html>

Changelog

Changelog

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 2.0.1
    1
    • latest

Version History

Package Sidebar

Install

npm i metalsmith-html-glob

Weekly Downloads

1

Version

2.0.1

License

GPL-3.0-or-later

Unpacked Size

46.9 kB

Total Files

6

Last publish

Collaborators

  • emmercm