Skip to content

Commit

Permalink
Make ability to pass all extracted pages to template in PagePlugin
Browse files Browse the repository at this point in the history
  • Loading branch information
kisenka committed Jun 2, 2016
1 parent c150243 commit 75d6612
Showing 1 changed file with 15 additions and 10 deletions.
25 changes: 15 additions & 10 deletions lib/plugins/PagePlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,25 +35,30 @@ PagePlugin.prototype.apply = function (compiler) {
var promises = results.filter(function (result) {
return result instanceof DocPage;
})
.map(function(page) {
var filename = interpolateName(plugin.options.filename, {
path: page.source.absolutePath,
context: compilation.compiler.context
});

page.path = filename;

return page;
})
.map(function (page) {
var source = page.source;
var compiler = new TemplateCompiler(compilation, plugin.options.template, true);

return compiler.run().then(function (template) {
var templateContext = extend(true, {}, plugin.options.context, {
page: page.serialize()
page: page.serialize(),
pages: context.plugin.docs.map(function(doc) {
return doc.serialize()
})
});

var result = template(templateContext);
var filename = interpolateName(plugin.options.filename, {
path: source.absolutePath,
context: compilation.compiler.context,
content: result
});

page.path = filename;
emitFile(compilation, page.path, result);

emitFile(compilation, filename, result);
return true;
});
});
Expand Down

0 comments on commit 75d6612

Please sign in to comment.