metalsmith / layouts

A metalsmith plugin for layouts
MIT License
116 stars 49 forks source link

Loosen dependency on jstransformers #179

Open webketje opened 2 years ago

webketje commented 2 years ago

Some of the JS transformers are severely outdated and due to the update mechanism (jstransformer-boilerplate -> test-jstransformer -> jstransformer-*) this is probably going to keep being an issue in the future.

For example:

Furthermore the renderAsync method used in layouts is not guaranteed to be present on all jstransformers.

There are a few options:

  1. Fork & republish a selection of the most commonly used jstransformers.
  2. Narrow the selection of supported templating languages (eg markdown, handlebars, nunjucks, twig) by bundling adapters in metalsmith-layouts, and specifying peerDependencies and peerDependenciesMeta: optional
  3. Keep using jstransformers, but provide an option transformers: ['path/to/transformer.js', 'path/to/other/transformer.js]` that will be added to the cache with the node_modules transformers, update the docs explaining how to create your own jstransformer.

In favor of option 3

webketje commented 2 years ago

I've become member of the jstransformer's org and have updated the 2 jstransformers mentioned. I still think providing a transformers option has several advantages:

  1. It has to be explicitly passed with require('jstransformer-nunjucks') -> explicit is better than implicit
  2. It makes inputformat-to-jstransformer obsolete, which does a dictionary - key lookup of rendering engines matching an ext. 3. Instead, the transformer's inputFormat properties can be used, this allows custom matching & custom transformers
  3. No need for caching the rendering engine

Disadvantages:

webketje commented 5 months ago

To be aligned with @metalsmith/in-place 5.x transform option