diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-27 18:05:13 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-27 18:05:13 +0200 |
commit | 54f530c7c36105698958908272e79935a56bf25f (patch) | |
tree | 7d01ad53a8013595461e5128b4b5140317df0f3e /lib/generate/site/index.js | |
parent | ca94055adf2d0519105b587116d5d56b559a2c3a (diff) | |
parent | 9fdc5da22da283f8c3a76760194bf2f61a8cebd4 (diff) | |
download | gitbook-54f530c7c36105698958908272e79935a56bf25f.zip gitbook-54f530c7c36105698958908272e79935a56bf25f.tar.gz gitbook-54f530c7c36105698958908272e79935a56bf25f.tar.bz2 |
Merge pull request #171 from GitbookIO/feature/offlineCache
Improve pages loading
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r-- | lib/generate/site/index.js | 32 |
1 files changed, 30 insertions, 2 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index 68328e7..f8986df 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -9,6 +9,7 @@ var parse = require("../../parse"); var BaseGenerator = require("../generator"); var indexer = require('./search_indexer'); +var Manifest = require('../manifest'); // Swig filter for returning the count of lines in a code section swig.setFilter('lines', function(content) { @@ -30,6 +31,10 @@ var Generator = function() { this.revision = Date.now(); this.indexer = indexer(); + this.manifest = new Manifest(Date.now()); + this.manifest.add("NETWORK", [ + '*' + ]); }; util.inherits(Generator, BaseGenerator); @@ -119,6 +124,8 @@ Generator.prototype.convertFile = function(content, _input) { }); }) .then(function(sections) { + that.manifest.add("CACHE", _output); + return that._writeTemplate(that.template, { progress: progress, @@ -157,11 +164,22 @@ Generator.prototype.copyAssets = function() { path.join(that.options.theme, "assets"), path.join(that.options.output, "gitbook") ) + + // Add to cach manifest + .then(function() { + return that.manifest.addFolder(path.join(that.options.output, "gitbook"), "gitbook"); + }) + // Copy plugins assets .then(function() { return Q.all( _.map(that.plugins.list, function(plugin) { - return plugin.copyAssets(path.join(that.options.output, "gitbook/plugins/", plugin.name)) + var pluginAssets = path.join(that.options.output, "gitbook/plugins/", plugin.name); + + return plugin.copyAssets(pluginAssets) + .then(function() { + return that.manifest.addFolder(pluginAssets, "gitbook/plugins/"+plugin.name); + }); }) ); }) @@ -175,9 +193,19 @@ Generator.prototype.writeSearchIndex = function() { ); }; + +// Add cache manifest +Generator.prototype.writeCacheManifest = function() { + return fs.writeFile( + path.join(this.options.output, 'manifest.appcache'), + this.manifest.dump() + ); +}; + Generator.prototype.finish = function() { return this.copyAssets() - .then(this.writeSearchIndex); + .then(this.writeSearchIndex) + .then(this.writeCacheManifest); }; module.exports = Generator; |