Skip to content

Commit

Permalink
fix(template): support both string and array
Browse files Browse the repository at this point in the history
  • Loading branch information
curbengh committed Nov 22, 2019
1 parent c13ebf6 commit f29ce2f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
10 changes: 4 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,17 @@ path = path.map(str => {
return str;
});

if (typeof template === 'string') {
if (template.length >= 1) template = [template];
if (typeof template !== 'string' && !Array.isArray(template)) {
template = null;
}

if (Array.isArray(template)) {
if (template.length >= 1) {
if (template.length > 2) template = template.slice(0, 2);
if (template.length < type.length) template.push(join(__dirname, `${type[1]}.xml`));
if (template.length > type.length) template = template.slice(0, type.length);
else if (template.length < type.length) template.push(join(__dirname, `${type[1]}.xml`));
} else {
template = null;
}
} else {
template = null;
}

config.type = type;
Expand Down
7 changes: 5 additions & 2 deletions lib/generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,11 @@ module.exports = function(locals, type, path) {
const config = this.config;
const feedConfig = config.feed;

const tmplSrc = feedConfig.template ? feedConfig.template[feedConfig.type.indexOf(type)]
: join(__dirname, `../${type}.xml`);
let tmplSrc = join(__dirname, `../${type}.xml`);
if (feedConfig.template) {
if (typeof feedConfig.template === 'string') tmplSrc = feedConfig.template;
else tmplSrc = feedConfig.template[feedConfig.type.indexOf(type)];
}
const template = nunjucks.compile(readFileSync(tmplSrc, 'utf8'), env);

let posts = locals.posts.sort(feedConfig.order_by || '-date');
Expand Down

0 comments on commit f29ce2f

Please sign in to comment.