diff options
author | Samy Pessé <samypesse@gmail.com> | 2016-02-18 10:45:50 +0100 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2016-02-18 10:45:50 +0100 |
commit | 1de9d5683b30b4f24c2aba4f796a6d77f0ce7004 (patch) | |
tree | d8d3b8a525949f40c741e0ae4e37839d40fb7466 /lib/output/website.js | |
parent | b66242db985fd8d6088b52d4b089f0de2ecb8058 (diff) | |
download | gitbook-1de9d5683b30b4f24c2aba4f796a6d77f0ce7004.zip gitbook-1de9d5683b30b4f24c2aba4f796a6d77f0ce7004.tar.gz gitbook-1de9d5683b30b4f24c2aba4f796a6d77f0ce7004.tar.bz2 |
Copy assets to output (website)
Diffstat (limited to 'lib/output/website.js')
-rw-r--r-- | lib/output/website.js | 45 |
1 files changed, 40 insertions, 5 deletions
diff --git a/lib/output/website.js b/lib/output/website.js index f58c68f..b595897 100644 --- a/lib/output/website.js +++ b/lib/output/website.js @@ -4,6 +4,7 @@ var util = require('util'); var nunjucks = require('nunjucks'); var Promise = require('../utils/promise'); +var fs = require('../utils/fs'); var conrefsLoader = require('./conrefs'); var Output = require('./base'); @@ -17,7 +18,7 @@ function templatesPath(dir) { return path.join(dir, '_layouts'); } -function WebsiteOutput() { +function _WebsiteOutput() { Output.apply(this, arguments); // Nunjucks environment @@ -29,7 +30,9 @@ function WebsiteOutput() { // Plugin instance for the default theme this.defaultTheme; } -util.inherits(WebsiteOutput, Output); +util.inherits(_WebsiteOutput, Output); + +var WebsiteOutput = conrefsLoader(_WebsiteOutput); // Name of the generator // It's being used as a prefix for templates @@ -53,12 +56,13 @@ WebsiteOutput.prototype.prepare = function() { throw new Error('Theme "' + themeName + '" is not installed, add "' + themeID(themeName) + '" to your "book.json"'); } + // This list is ordered to give priority to templates in the book var searchPaths = _.chain([ // The book itself can contains a "_layouts" folder - '_layouts', + that.book.root, // Installed plugin (it can be identical to themeDefault.root) - '_layouts', + that.theme.root, // Is default theme still installed that.themeDefault? that.themeDefault.root : null @@ -91,6 +95,37 @@ WebsiteOutput.prototype.prepare = function() { href = path.join('/gitbook', href); return that.resolveForPage(this.ctx.file.path, href); }); + }) + + // Copy assets before copyign files from book + .then(function() { + return Promise.serie([ + // Assets from the book are already copied + // The order is reversed from the template's one + + // Is default theme still installed + that.themeDefault && that.themeDefault.root != that.theme.root? + that.themeDefault.root : null, + + // Installed plugin (it can be identical to themeDefault.root) + that.theme.root + ], function(folder) { + if (!folder) return; + + // Copy assets only if exists (don't fail otherwise) + var assetFolder = path.join(folder, '_assets', that.name); + if (!fs.existsSync(assetFolder)) return; + + return fs.copyDir( + assetFolder, + that.resolve('gitbook'), + { + deleteFirst: false, // Delete "to" before + overwrite: true, + confirm: true + } + ); + }); }); }; @@ -128,4 +163,4 @@ WebsiteOutput.prototype.templateName = function(name) { return path.join(this.name, name+'.html'); }; -module.exports = conrefsLoader(WebsiteOutput); +module.exports = WebsiteOutput; |