Skip to content
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,7 @@ build/Release
# see https://npmjs.org/doc/faq.html#Should-I-check-my-node_modules-folder-into-git
node_modules

theme/javascript/vendors
theme/javascript/vendors

# vim swapfile
*.swp
18 changes: 18 additions & 0 deletions bin/gitbook.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ var Q = require('q');
var _ = require('lodash');
var path = require('path');
var prog = require('commander');
var tinylr = require('tiny-lr-fork');

var pkg = require('../package.json');
var generators = require("../lib/generate").generators;
Expand All @@ -26,9 +27,19 @@ build.command(prog.command('serve [source_dir]'))
.description('Build then serve a gitbook from a directory')
.option('-p, --port <port>', 'Port for server to listen on', 4000)
.option('--no-watch', 'Disable restart with file watching')
.option('--no-cache', 'Disable cache manifest generation')
.action(function(dir, options) {
var server = new Server();

// init livereload server
var lrOptions = {port: 35729};
var lrServer = tinylr(lrOptions);
var lrPath = undefined;
lrServer.listen(lrOptions.port, function(err) {
if (err) { return console.log(err); }
console.log('Live reload server started on port: ' + lrOptions.port);
});

var generate = function() {
if (server.isRunning()) console.log("Stopping server");

Expand All @@ -43,9 +54,16 @@ build.command(prog.command('serve [source_dir]'))
.then(function() {
console.log('Serving book on http://localhost:'+options.port);

if (lrPath) {
// trigger livereload
lrServer.changed({body:{files:[lrPath]}})
}

if (!options.watch) return;
return utils.watch(_options.input)
.then(function(filepath) {
// set livereload path
lrPath = filepath;
console.log("Restart after change in files");
console.log('');
return generate();
Expand Down
5 changes: 3 additions & 2 deletions lib/generate/plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,8 @@ Plugin.fromList = function(names, root) {
// Default plugins
Plugin.defaults = [
"mixpanel",
"mathjax"
"mathjax",
"livereload"
];

module.exports = Plugin;
module.exports = Plugin;
10 changes: 7 additions & 3 deletions lib/generate/site/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,9 +237,13 @@ Generator.prototype.writeCacheManifest = function() {
};

Generator.prototype.finish = function() {
return this.copyAssets()
.then(this.writeSearchIndex)
.then(this.writeCacheManifest);
var deferred = this.copyAssets().then(this.writeSearchIndex);

if (this.options.cache) {
deferred = deferred.then(this.writeCacheManifest);
}

return deferred;
};

module.exports = Generator;
5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@
"semver": "2.2.1",
"gaze": "~0.5.1",
"resolve": "0.6.3",

"tiny-lr-fork": "0.0.5",
"gitbook-plugin": "0.0.2",
"gitbook-plugin-mixpanel": "0.0.2",
"gitbook-plugin-mathjax": "0.0.3"
"gitbook-plugin-mathjax": "0.0.3",
"gitbook-plugin-livereload": "0.0.1"
},
"devDependencies": {
"mocha": "1.18.2",
Expand Down
6 changes: 5 additions & 1 deletion theme/templates/site.html
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{% extends "layout.html" %}

{% block htmlTag %}manifest="{{ basePath }}/manifest.appcache"{% endblock %}
{% block htmlTag %}
{% if options.cache %}
manifest="{{ basePath }}/manifest.appcache"
{% endif %}
{% endblock %}
{% block title %}{{ progress.current.title }}{% parent %}{% endblock %}
{% block content %}
<div class="book" {% if githubId %}data-github="{{ githubId }}"{% endif %} data-level="{{ progress.current.level }}" data-basepath="{{ basePath }}" data-revision="{{ revision }}">
Expand Down