mirror of
https://github.com/vale981/metalsmith-layouts
synced 2025-03-04 17:21:37 -05:00
Allow to omit template extensions.
This commit is contained in:
parent
65aaa7857e
commit
c4500d3b29
1 changed files with 13 additions and 2 deletions
15
lib/index.js
15
lib/index.js
|
@ -30,6 +30,7 @@ var settings = [
|
|||
'engine',
|
||||
'partials',
|
||||
'partialExtension',
|
||||
'layoutExtension',
|
||||
'pattern',
|
||||
'rename',
|
||||
'exposeConsolidate',
|
||||
|
@ -80,6 +81,7 @@ function plugin(opts){
|
|||
var dir = opts.directory || 'layouts';
|
||||
var engine = opts.engine;
|
||||
var partialExtension = opts.partialExtension;
|
||||
var layoutExtension = opts.layoutExtension || '';
|
||||
var partials = opts.partials;
|
||||
var pattern = opts.pattern;
|
||||
var rename = opts.rename;
|
||||
|
@ -107,6 +109,15 @@ function plugin(opts){
|
|||
}
|
||||
}
|
||||
|
||||
function getLayoutPath(layout) {
|
||||
layout = layout || def;
|
||||
|
||||
if(!/\./.test(layout.split('/').pop()))
|
||||
layout += '.' + layoutExtension;
|
||||
|
||||
return layout;
|
||||
}
|
||||
|
||||
/**
|
||||
* Stringify files that pass the check, pass to matches
|
||||
*/
|
||||
|
@ -118,7 +129,7 @@ function plugin(opts){
|
|||
debug('stringifying file: %s', file);
|
||||
var data = files[file];
|
||||
data.contents = data.contents.toString();
|
||||
var template = metalsmith.path(dir, data[layoutKey] || def);
|
||||
var template = metalsmith.path(dir, getLayoutPath(data[layoutKey]));
|
||||
|
||||
if (!templates[template]) {
|
||||
debug('found new template: %s', template);
|
||||
|
@ -138,7 +149,7 @@ function plugin(opts){
|
|||
// Deep clone params (by passing 'true')
|
||||
var clonedParams = extend(true, {}, params);
|
||||
var clone = extend({}, clonedParams, metadata, data);
|
||||
var str = metalsmith.path(dir, data[layoutKey] || def);
|
||||
var str = metalsmith.path(dir, getLayoutPath(data[layoutKey]));
|
||||
var render = consolidate[engine];
|
||||
|
||||
// Rename file if necessary
|
||||
|
|
Loading…
Add table
Reference in a new issue