layouts icon indicating copy to clipboard operation
layouts copied to clipboard

the default glob pattern is not `**/*` for 'nunjucks' transform

Open AndreKelling opened this issue 9 months ago • 1 comments

in the current Options Docs https://github.com/metalsmith/layouts/tree/v3.0.0?tab=readme-ov-file#options its written, that pattern option has a default of **/*.

In the JS DocBlock it is written as pattern='**' which is different again.

But actually it is falling to **/*.{${inputFormats.join(',')}} which is with a transform of 'nunchucks' then '**/*.{njk,nunjucks}'. See here https://github.com/metalsmith/layouts/blob/v3.0.0/src/index.js#L74

The pattern '**/*.{njk,nunjucks}' is not matching any .html files.

Where i guess the html files are what is desired to match here.

At least its working with pattern: "**/*.html", on my side and i am just a bit confused.

But of course props for all the good work over that long time!!

AndreKelling avatar Apr 08 '25 21:04 AndreKelling

This is indeed a documentation inconsistency (I forgot to update the docblock/readme in places) but the behavior is correct.
The reason people previously targeted **/*.html by default is because plugins like permalinks were often run first and not flexible enough. With the advent of the extname option in metalsmith/layouts & in-place (and soon, markdown), as well as, directoryIndex for permalinks, one can do:

Metalsmith('.')
  .use(markdown())
  .use(permalinks({ trailingSlash: '/', directoryIndex: 'index.njk' }))
  .use(inPlace({ transform: 'nunjucks', extname: '.njk' }))
  .use(layouts({ transform: 'nunjucks' }))

// file changes like this over each plugin
// 'blog.md'
// 'blog.html'
// 'blog/index.njk'
// 'blog/index.njk'
// 'blog/index.html'

webketje avatar Apr 09 '25 13:04 webketje