-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Common use case enhancements #179
Comments
On second thought, the multiple file extension in order processing makes the plugin way too complicated. Problems encountered are mainly incompatibilities between multiple parsers, syntax highlighting mismatch for the user, and a harder to follow debug trace for the recursive render function. For example the Multiple file extension in order processing should not be an inherent part of a single run of this plugin. The same can be accomplished with 2 runs of in-place and configurable extension handling: const markedTransformer = require('jstransformer-marked')
const customTransformer = {
inputFormats: ['html'],
render(str) {
return str.replace('Hello', 'Bye')
}
}
// by default pattern would always be new RegExp(`**/*.{${transformer.inputFormats.join('|')}}*`)
// can still be overwritten with pattern option
// in example below, using the extname option, a file 'index.njk.md' would first be renamed to 'index.md', then to 'index.html', then the extension would be left untouched.
metalsmith
.use(inPlace({
// can do the require/import behind-the-scenes, required for CLI
// also works with local transformers eg './my-transform.js'
transform: 'jstransformer-nunjucks',
extname: 'remove',
engineOptions: { }
}))
.use(inPlace({
transform: markedTransformer,
extname: 'replace'
}))
.use(inPlace({
transform: customTransformer,
extname: 'keep'
})) |
First some observations:
index.njk.njk.md.njk.md
)"jstransformer-local": "file:jstransformer-local"
index.ejs.md.njk.twig.hbs
if all transformers are installed, nobody in their right mind would mix 5 templating languages with conflicting syntaxes.@metalsmith/markdown
orjstransformer-marked
with in-place, the desirable extension order is always*.md
at the end to enable markdown syntax highlighting in code editors. But running markdown before other transformers is highly likely to garble the intermixed syntax. An alternative to combining markdown is registering a custom markdown helper in the template language of choiceThe second is to use in-place only and use templating constructs inside content files with "slots", eg for nunjucks:
{% extends 'layout.njk' %}
. The first is convenient because layouts can be applied through file frontmatter (or assigned with plugins). The second needs to "wrap" the content in each file. However, both plugins rename the extensions to html, which forces the second one to use a target pattern ending in.html
.Some potential solutions:
engineOptions: { marked: {...}, nunjucks: {...}
false|true|<ext>
The text was updated successfully, but these errors were encountered: