diff options
-rw-r--r-- | lib/generate/fs.js | 1 | ||||
-rw-r--r-- | lib/generate/page/index.js | 4 | ||||
-rw-r--r-- | lib/generate/site/index.js | 21 | ||||
-rw-r--r-- | theme/templates/website/page.html | 19 |
4 files changed, 36 insertions, 9 deletions
diff --git a/lib/generate/fs.js b/lib/generate/fs.js index 50219eb..371051c 100644 --- a/lib/generate/fs.js +++ b/lib/generate/fs.js @@ -87,5 +87,6 @@ module.exports = { fs.exists(path, d.resolve); return d.promise; }, + existsSync: fs.existsSync, readFileSync: fs.readFileSync.bind(fs) }; diff --git a/lib/generate/page/index.js b/lib/generate/page/index.js index a926d13..c5f9420 100644 --- a/lib/generate/page/index.js +++ b/lib/generate/page/index.js @@ -11,6 +11,8 @@ var BaseGenerator = require("../site"); var Generator = function() { BaseGenerator.apply(this, arguments); + this.styles = ["ebook"]; + // Base for assets in plugins this.pluginAssetsBase = "ebook"; @@ -49,7 +51,7 @@ Generator.prototype.finish = function() { var output = path.join(this.options.output, "index.html"); var progress = parse.progress(this.options.navigation, "README.md"); - + return Q() // Write table of contents diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index 94ee6c0..dfdbf68 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -18,6 +18,7 @@ var Generator = function() { // Attach methods to instance _.bindAll(this); + this.styles = ["website"]; this.revision = Date.now(); this.indexer = indexer(); }; @@ -29,10 +30,28 @@ Generator.prototype.load = function() { return BaseGenerator.prototype.load.apply(this) .then(function() { + return that.loadStyles(); + }) + .then(function() { return that.loadTemplates(); }); }; +// Load all styles +Generator.prototype.loadStyles = function() { + var that = this; + this.styles = _.chain(this.styles) + .map(function(style) { + var stylePath = that.options.styles[style]; + if (fs.existsSync(path.resolve(that.options.input, stylePath))) { + return stylePath; + } + return null; + }) + .compact() + .value(); +}; + // Load all templates Generator.prototype.loadTemplates = function() { this.template = swig.compileFile( @@ -54,6 +73,8 @@ Generator.prototype._writeTemplate = function(tpl, options, output, interpolate) return Q() .then(function(sections) { return tpl(_.extend({ + styles: that.styles, + revision: that.revision, title: that.options.title, diff --git a/theme/templates/website/page.html b/theme/templates/website/page.html index 1d5db62..91f2162 100644 --- a/theme/templates/website/page.html +++ b/theme/templates/website/page.html @@ -66,12 +66,15 @@ require(["gitbook"], function(gitbook) { {% endblock %} {% block style %} -<link rel="stylesheet" href="{{ staticBase }}/style.css"> -{% for resource in plugins.resources.css %} - {% if resource.url %} - <link rel="stylesheet" href="{{ resource.url }}"> - {% else %} - <link rel="stylesheet" href="{{ staticBase }}/plugins/{{ resource.path }}"> - {% endif %} -{% endfor %} + <link rel="stylesheet" href="{{ staticBase }}/style.css"> + {% for resource in plugins.resources.css %} + {% if resource.url %} + <link rel="stylesheet" href="{{ resource.url }}"> + {% else %} + <link rel="stylesheet" href="{{ staticBase }}/plugins/{{ resource.path }}"> + {% endif %} + {% endfor %} + {% for style in styles %} + <link rel="stylesheet" href="{{ basePath }}/{{ style }}"> + {% endfor %} {% endblock %} |