mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-24 11:26:31 +00:00
Use _layouts folders as base for templates
This commit is contained in:
+15
-4
@@ -12,6 +12,11 @@ function themeID(plugin) {
|
||||
return 'theme-' + plugin;
|
||||
}
|
||||
|
||||
// Directory for a theme with the templates
|
||||
function templatesPath(dir) {
|
||||
return path.join(dir, '_layouts');
|
||||
}
|
||||
|
||||
function WebsiteOutput() {
|
||||
Output.apply(this, arguments);
|
||||
|
||||
@@ -50,15 +55,16 @@ WebsiteOutput.prototype.prepare = function() {
|
||||
|
||||
var searchPaths = _.chain([
|
||||
// The book itself can contains a "_layouts" folder
|
||||
that.book.root,
|
||||
'_layouts',
|
||||
|
||||
// Installed plugin (it can be identical to themeDefault.root)
|
||||
that.theme.root,
|
||||
'_layouts',
|
||||
|
||||
// Is default theme still installed
|
||||
that.themeDefault? that.themeDefault.root : null
|
||||
])
|
||||
.compact()
|
||||
.map(templatesPath)
|
||||
.uniq()
|
||||
.value();
|
||||
|
||||
@@ -87,8 +93,13 @@ WebsiteOutput.prototype.prepare = function() {
|
||||
WebsiteOutput.prototype.onPage = function(page) {
|
||||
var that = this;
|
||||
|
||||
// Parse the page
|
||||
return page.toHTML(this)
|
||||
|
||||
// Render the page template with the same context as the json output
|
||||
return this.render('page', this.getPageContext(page))
|
||||
.then(function() {
|
||||
return that.render('page', that.getPageContext(page));
|
||||
})
|
||||
|
||||
// Write the HTML file
|
||||
.then(function(html) {
|
||||
@@ -109,7 +120,7 @@ WebsiteOutput.prototype.render = function(tpl, context) {
|
||||
|
||||
// Return a complete name for a template
|
||||
WebsiteOutput.prototype.templateName = function(name) {
|
||||
return path.join('_layouts', this.name, name+'.html');
|
||||
return path.join(this.name, name+'.html');
|
||||
};
|
||||
|
||||
module.exports = conrefsLoader(WebsiteOutput);
|
||||
|
||||
Reference in New Issue
Block a user