Closed oupala closed 9 years ago
While debugging with metalsmith debug, I can see the following debug statements :
'tags/html/index.html':
{ template: 'tag.hbt',
contents: '',
tag: 'html',
pagination:
{ num: 1,
pages: [Object],
tag: 'html',
files: [Object] } },
I think that the empty value in the content
field might explain the empty generated file.
I've also encountered this same problem, as you said it is because metalsmith-templates is a dependency of metalsmith-tags. This plugin uses the metadata template
whereas metalsmith-layouts requires the use of layout
instead to provide the template/layout for the file. Below are a couple of solutions that I hope will help
Changing its reference at L138 from template
to layout
has made it work perfectly fine.
// Generate a new file based on the filename with correct metadata.
var page = {
layout: opts.template,
contents: '',
tag: tag,
pagination: {
num: i + 1,
pages: pages,
tag: tag,
files: pageFiles
}
};
layout
property using the template
property.This solution requires no messing with the plugin internals and only add a new layout field if there is not one already and a template field available.
.use(function (files, metalsmith, done) {
Object.keys(files).forEach(function (file) {
var data = files[file];
// Only messes with metadata if there is no layout and a template
if (!data.layout && data.template) {
data.layout = data.template;
}
});
done();
})
At the same time I also forked the plugin and made the changes to make it so that metalsmith-layouts is used instead of metalsmith-templates brianbrewer/metalsmith-tags
Thanks @brianbrewer for all these suggestions.
I'll go with solution no 2 for the moment.
Since the issue is fixed in another fork, it might be the right moment to merge brianbrewer/metalsmith-tags fork to master... If @hswolff could do this and publish to npmjs.org, it would be great !
Surprisingly, @brianbrewer solutions 1 and 2 do not work for me. Fortunately, solution 3 works prefectly.
Could you please open a pull request so that your fork is merged back to the official plugin, and published on npmjs.org ?
Awesome work @oupala and @brianbrewer, it's much much much appreciated!
Merged your changes @brianbrewer. I also added back deprecated usage of metalsmith-templates
so this plugin will support both for the time being.
Published changes as 0.11.0
.
I'm a happy user of metalsmith-tags and I have recently encountered a problem with this metalsmith plugin. The reason is that metalsmith-templates is a declared dependancy of metalsmith-tags. The problem is that metalsmith-templates is now deprecated (as you can read on the README file and has been replaced by metalsmith-layouts.
Do you think it could be possible to replace metalsmith-templates by metalsmith-layout ?
When I use metalsmith-tags 0.10.1, I get empty generated files (the file exist but contains no content at all) for tag pages.