Metalsmith 2.6 released
← News overviewMetalsmith 2.6 is out!
Github release | Github Roadmap 2.6 issue | NPM package | Node >= 14.14.0
Highlights
Typescript support included. No need to install the extra @metalsmith/types package anymore.
NodeJS < 14.14 support dropped: In line with the compatibility & support policy Node 14 support was dropped (EOL 2023-04-30). To be able to make use of Node's recursive fs.rm method and remove the rimraf dependency, support for the first 14 minor Node 14 versions was also dropped.
Power to the metalsmith CLI. Metalsmith 2.6 modernizes the CLI and adds 3 command-line options:
--env varname=varvalue
,--debug
(=--env debug=true
), and--dry-run
. These options overwrite those defined in a metalsmith build or config file allowing you to do faster test runs with different configurations.Metalsmith CLI now supports reading JS configs. That's right, now you can use a
metalsmith.js
(or.cjs
or.mjs
) file instead ofmetalsmith.json
, which allows you to preprocess input more easily. The examples below can be run withmetalsmith
ormetalsmith build
ormetalsmith -c metalsmith.mjs
:
Alternatively you can also run a full metalsmith build with the CLI now if the build is exported without actual build()
or process()
call:
- New Metalsmith.watch method. Metalsmith includes a watch method based on chokidar. The method is an options setter similar to Metalsmith.ignore and can be used both with Metalsmith.build (output to filesystem) and Metalsmith.process (only process in-memory).
It supports full rebuilds and partial rebuilds by setting metalsmith.clean()
to true
or false
, respectively. A side-effect of using watching is that the build
and process
methods can not be awaited. Instead pass a callback to them that will be executed on each rebuild/ reprocess. In partial rebuild mode, the files parameter passed to the callback will only contain changed files!
Have a look at the snippet below to get a better idea of how it works:
import { fileURLToPath } from 'node:url'
import { dirname } from 'node:path'
import Metalsmith from 'metalsmith'
const __dirname = dirname(fileURLToPath(import.meta.url))
Metalsmith(__dirname)
// watches metalsmith.source() by default
.watch(true)
// watch custom dirs, override chokidar options
.watch(['layouts', 'src'], { interval: 2000 })
// clean: true for full rebuild, false for partial
.clean(false)
// output files...
.build(funtion onEachRebuild(err, files) {
// if clean:false, files will only be the changed files!
console.log('Rebuild finished!')
})
// or only do a 'dry-run' (no writes)
.process(funtion onEachReprocess(err, files) {
// if clean:false, files will only be the changed files!
console.log('Reprocessed!')
})
- New
Metalsmith#matter
member available. Every Metalsmith instance now comes with amatter
member that exposes the parse, stringify, wrap and options methods. The primary goal is to allow plugins to use these methods instead of having to require js-yaml or other parsing libraries separately, with clashing versions, or different parsing configs.
The snippet below demonstrates usage of these methods:
// syncs with metalsmith.frontmatter() options
metalsmith.matter.options({ excerpt: true })
metalsmith.matter.parse(`---\ntitle: Hello world\n---\nExcerpt\n---`)
// returns { title: 'Hello World', excerpt: 'Excerpt' }
metalsmith.matter.stringify({ title: 'Hello World', excerpt: 'Excerpt' })
// returns '---\ntitle: Hello world\nexcerpt: Excerpt---'
metalsmith.matter.wrap('title: Hello world\nexcerpt: Excerpt')
// returns '---\ntitle: Hello world\nexcerpt: Excerpt---'
Full Release notes
Added
- #356 Added Typescript support
58d22a3
- Added --debug and --dry-run options to metalsmith (build) command
2d84fbe
- Added --env option to metalsmith (build) command
9661ddc
- Added Metalsmith CLI support for loading a .(c)js config. Reads from metalsmith.js as second default after metalsmith.json
45a4afe
- Added support for running (C/M)JS config files from CLI
424e6ec
- Dependencies:
Removed
Updated
- Modernized Metalsmith CLI, prepared transition to imports instead of require
24fcffb
4929bc2
- Dependencies: