metalsmith / layouts

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

Ignoring the output format specified in the jstransformer #176

Closed aumouvantsillage closed 3 years ago

aumouvantsillage commented 3 years ago

I am trying to generate an atom feed using metalsmith-layouts and nunjucks. When running Metalsmith with debuging on, I get the following error:

metalsmith-layouts validating atom.xml +0ms
metalsmith-layouts validation failed, no jstransformer found for layout for atom.xml +0ms

I assume that metalsmith-layouts tries to find a jstransformer that supports XML files, but unfortunately, jstransformer-nunjucks only has "html" set as its output format.

Do you think that this issue could be addressed by metalsmith-layouts allowing to override or ignore the output format specified in jstransformers. Or should I report this issue to jstransformer-nunjucks?

As a workaround, I assume I can generate my atom feed as atom.html and rename it to atom.xml later.

aumouvantsillage commented 3 years ago

The error message was caused by a mistake in the template file name. Now I get the following messages:

metalsmith-layouts validating atom.xml +0ms
...
metalsmith-layouts rendering atom.xml with layout atom.njk +0ms
...
metalsmith-layouts done rendering atom.xml +4ms

However, the atom.xml file in my build folder is still empty.

aumouvantsillage commented 3 years ago

When I rename the source file atom.xml to atom.html, metalsmith-layouts outputs a non-empty atom.html file.

ismay commented 3 years ago

It's hard for me to say what's going on exactly without taking a look at your source. All the tests are passing so it seems like everything is working as expected. For doing what you're trying to do here, I'd say metalsmith-layouts is not a good match. Layouts is meant to wrap files in your source folder with a layout. If you're trying to transform content that's in your source folder you'll want metalsmith-in-place.

With that, you could just create something like atom.xml.njk. If you have the nunjucks transformer installed, in-place would then process the nunjucks syntax and remove the .njk extension, meaning you'd end up with atom.xml.

I'll close this issue since this is more a question about usage, and there doesn't seem to be a bug. For further questions try the gitter chat: https://gitter.im/metalsmith/community. If you do encounter a bug, please open a PR with a failing test. Thanks!

aumouvantsillage commented 3 years ago

If you're trying to transform content that's in your source folder you'll want metalsmith-in-place.

It's not exactly what I was trying to do. I had a file atom.xml in my source folder that looked like this:

---
layout: atom.njk
---

and a file atom.njk in my templates folder.

With that, you could just create something like atom.xml.njk

Yes. This solution works for me. However, it does not explain why metalsmith-layouts did not work.

I'll close this issue since this is more a question about usage, and there doesn't seem to be a bug.

For your information, I was updating a site that used the old metalsmith-templates plugin. Migrating to metalsmith-layouts, with the same sources and templates, worked fine except for the atom.xml file.

So, from my point of view, I still consider that there is a bug. I will try to reproduce the issue with a minimal example and I'll send you a PR.

ismay commented 3 years ago

It's not exactly what I was trying to do. I had a file atom.xml in my source folder that looked like this:

---
layout: atom.njk
---

and a file atom.njk in my templates folder.

I understand. Metalsmith-in-place is still better suited to that usecase. If there's no content in atom.xml then it's more straightforward to just place the contents of atom.njk in atom.xml and use in-place. Layouts is just sugar for templating engines that don't support inheritance like handlebars, you don't need it for nunjucks.

Yes. This solution works for me. However, it does not explain why metalsmith-layouts did not work.

True, that's hard to assess for me without a look at your source.

For your information, I was updating a site that used the old metalsmith-templates plugin. Migrating to metalsmith-layouts, with the same sources and templates, worked fine except for the atom.xml file.

So, from my point of view, I still consider that there is a bug. I will try to reproduce the issue with a minimal example and I'll send you a PR.

Metalsmith-templates is very different from the current versions of layouts and in-place, so be aware differences are expected. Templates did not look at extensions, but used an engine configured in the options. It was also based on consolidate instead of jstransformers.

If you've encountered a bug, please make sure that the usecase is supported by the goals outlined in the readme and open a PR with a failing test that demonstrates the bug you've found.