Closed saneef closed 9 years ago
Difficult to tell with just the error. Metalsmith-layouts should always return file.contents
unaltered or as a buffer (see here). Which is exactly the same as what metalsmith-templates did.
So I'm not sure why you're getting this error after your switch to metalsmith-layouts. Try and set up a reduced test case. That way it'll be easier to isolate the problem.
@ismay Sure. Will try with a reduced test case
Ok, I'll close this because it doesn't appear to be a metalsmith-layouts specific problem. But if the problem is due to metalsmith-layouts please let me know!
@ismay I created a tiny test project for isolating this bug. Here is the link https://github.com/saneef/metalsmith-layouts-test. It has only template rendering, and works fine with metalsmith-templates
but fails with metalsmith-layouts
.
I'd say that this issue is gulpsmith related. Try and debug what's going wrong with gulpsmith, because metalsmith-layouts shouldn't be returning any file.contents
that aren't buffers.
From your setup it seems like you don't have any problems with your configuration at least, as far as metalsmith is concerned.
Will check. But it's quite strange since both metalsmith-in-place
and metalsmith-templates
works with gulpsmith.
I agree. Still, if metalsmith-layouts by itself wouldn't properly return file.contents we'd be seeing this error without gulpsmith as well. So I'd say this is an interaction with gulpsmith, on gulpsmith's side. Let me know if you find anything specific that metalsmith-layouts is doing wrong though.
By the way, you've probably noticed this yourself already, but you're missing a layout
key in the front-matter in your source. That would at least explain why it isn't applying a layout. It will however still pass the file through unmodified, see here.
Let me know if you find out anything more.
Yes, you are right.
I found that hard way. Unfortunately, the contents
getting from gulpsmith
as well as gulp-smith
is String
. There is in no ignore case (when meta data layout is note present) like in metalsmith-layouts
for metalsmith-templates
and metalsmith-in-place
. So didn't see any errors. :disappointed:
Unfortunately, the contents getting from gulpsmith as well as gulp-smith is String
I don't know if I understand exactly what you mean, but contents
shouldn't be a String
. See if gulpsmith changes file.contents
in any way.
Yes, it's shouldn't be in String
but it is.
I added console.log(typeof data.contents);
after the line https://github.com/superwolff/metalsmith-layouts/blob/master/lib/index.js#L108, and run with gulpsmith
. And, the result is string
. Sigh.
Well at that point it should be a string. It's converted back to a buffer here. Check with gulpsmith. This shouldn't be a metalsmith-layouts issue.
The error is at line 112: because of the early exit, files without a layout are left as strings and not converted back to buffers.
Ah that's probably it. Thanks for reporting!
@saneef This should be fixed in 1.4.1, could you confirm if this solves the error you were getting? Thanks for reporting this btw.!
Yes, it worked!
:+1: Cool, thanks again for reporting the bug and replying so quickly!
I was using
metalsmith-templates
so far. Since it's deprecated, today I decided to usemetalsmith-layouts
. I use gulpsmith so I can use metalsmith with gulp. But, I'm getting this error when I started usingmetalsmith-layouts
. Any ideas why it is happening?