metalsmith.use/ match enhancement

Author: webketjeCreated May 8, 2024Updated May 8, 2024
Labelsstage:drafttype:feature

When a Metalsmith instance is intantiated, it can have a property indicating its pristine state. When run is first called it is assigned a different value. This property can be used to determine whether a function call happened during instantiation or during the first run. Then the match method could be used as a built-in to replace the pattern option in many plugins.

javascript
metalsmith.use(drafts()) // match all
metalsmith.match('**/*.html').use(minifyHtml) // match html only for following plugins

Equally if not more appealing, and very similar to express js routers:

javascript
metalsmith.use('**/*.html', minfiyHtml)

though this has implications for the metalsmith.json CLI format in how array parameters vs function arguments are interpreted