diff options
-rw-r--r-- | README.md | 6 | ||||
-rw-r--r-- | lib/generate/config.js | 8 | ||||
-rw-r--r-- | lib/generate/ebook/index.js | 11 | ||||
-rw-r--r-- | lib/generate/fs.js | 1 | ||||
-rw-r--r-- | lib/generate/page/index.js | 5 | ||||
-rw-r--r-- | lib/generate/site/index.js | 31 | ||||
-rw-r--r-- | theme/templates/ebook/glossary.html | 2 | ||||
-rw-r--r-- | theme/templates/ebook/page.html | 19 | ||||
-rw-r--r-- | theme/templates/ebook/summary.html | 13 | ||||
-rw-r--r-- | theme/templates/website/glossary.html (renamed from theme/templates/book/glossary.html) | 0 | ||||
-rw-r--r-- | theme/templates/website/includes/exercise.html (renamed from theme/templates/book/includes/exercise.html) | 0 | ||||
-rw-r--r-- | theme/templates/website/includes/font-settings.html (renamed from theme/templates/book/includes/font-settings.html) | 0 | ||||
-rw-r--r-- | theme/templates/website/includes/header.html (renamed from theme/templates/book/includes/header.html) | 0 | ||||
-rw-r--r-- | theme/templates/website/includes/quiz.html (renamed from theme/templates/book/includes/quiz.html) | 0 | ||||
-rw-r--r-- | theme/templates/website/includes/summary.html (renamed from theme/templates/book/includes/summary.html) | 0 | ||||
-rwxr-xr-x | theme/templates/website/langs.html (renamed from theme/templates/book/langs.html) | 2 | ||||
-rw-r--r--[-rwxr-xr-x] | theme/templates/website/layout.html (renamed from theme/templates/layout.html) | 0 | ||||
-rw-r--r-- | theme/templates/website/page.html (renamed from theme/templates/book/page.html) | 21 |
18 files changed, 78 insertions, 41 deletions
@@ -212,9 +212,13 @@ The best resolution is **1800x2360**. The generation of the cover can be done au A small version of the cover can also be set by creating a file: **/cover_small.jpg**. +#### Custom Styles + +You can use your own custom stylesheet to change the style of the website or ebooks (pdf, epub, mobi). Create a `styles/website.css` (only for website output), `styles/ebook.css` (for all ebook outputs), `styles/pdf.css` (only for pdf output), `styles/epub.css` (for epub output) or `styles/mobi.css` (for mobi output). These paths can be changed in the `book.json`. + #### Publish your book -The platform [GitBook.io](https://www.gitbook.io/) is like an "Heroku for books": you can create a book on it (public, paid, or private) and update it using **git push**. +The platform [GitBook.com](https://www.gitbook.com/) is like an "Heroku for books": you can create a book on it (public, paid, or private) and update it using **git push**. #### Plugins diff --git a/lib/generate/config.js b/lib/generate/config.js index fb232a6..e198c91 100644 --- a/lib/generate/config.js +++ b/lib/generate/config.js @@ -65,6 +65,14 @@ var CONFIG = { } }, + // CSS Styles + "styles": { + "website": "styles/website.css", + "ebook": "styles/ebook.css", + "pdf": "styles/pdf.css", + "mobi": "styles/mobi.css", + "epub": "styles/epub.css" + }, // Options for PDF generation "pdf": { diff --git a/lib/generate/ebook/index.js b/lib/generate/ebook/index.js index 4ecccec..c74ffcd 100644 --- a/lib/generate/ebook/index.js +++ b/lib/generate/ebook/index.js @@ -11,6 +11,12 @@ var stringUtils = require("../../utils/string"); var Generator = function() { BaseGenerator.apply(this, arguments); + + // eBook format + this.ebookFormat = this.options.extension || path.extname(this.options.output).replace("\.", "") || "pdf"; + + // Styles to use + this.styles = ["ebook", this.ebookFormat]; }; util.inherits(Generator, BaseGenerator); @@ -20,7 +26,6 @@ Generator.prototype.finish = function() { return BaseGenerator.prototype.finish.apply(this) .then(function() { var d = Q.defer(); - var format = that.options.extension || path.extname(that.options.output).replace("\.", "") || "pdf"; if (!that.options.cover && fs.existsSync(path.join(that.options.output, "cover.jpg"))) { that.options.cover = path.join(that.options.output, "cover.jpg"); @@ -44,7 +49,7 @@ Generator.prototype.finish = function() { "--breadth-first": true }; - if (format == "pdf") { + if (that.ebookFormat == "pdf") { var pdfOptions = that.options.pdf; _.extend(_options, { @@ -64,7 +69,7 @@ Generator.prototype.finish = function() { var command = [ "ebook-convert", path.join(that.options.output, "SUMMARY.html"), - path.join(that.options.output, "index."+format), + path.join(that.options.output, "index."+that.ebookFormat), stringUtils.optionsToShellArgs(_options) ].join(" "); 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..8054fe6 100644 --- a/lib/generate/page/index.js +++ b/lib/generate/page/index.js @@ -11,6 +11,9 @@ var BaseGenerator = require("../site"); var Generator = function() { BaseGenerator.apply(this, arguments); + // Styles to use + this.styles = ["ebook"]; + // Base for assets in plugins this.pluginAssetsBase = "ebook"; @@ -49,7 +52,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 4d8803e..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,20 +30,38 @@ 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( - this.plugins.template("site:page") || path.resolve(this.options.theme, 'templates/book/page.html') + this.plugins.template("site:page") || path.resolve(this.options.theme, 'templates/website/page.html') ); this.langsTemplate = swig.compileFile( - this.plugins.template("site:langs") || path.resolve(this.options.theme, 'templates/book/langs.html') + this.plugins.template("site:langs") || path.resolve(this.options.theme, 'templates/website/langs.html') ); this.glossaryTemplate = swig.compileFile( - this.plugins.template("site:glossary") || path.resolve(this.options.theme, 'templates/book/glossary.html') + this.plugins.template("site:glossary") || path.resolve(this.options.theme, 'templates/website/glossary.html') ); }; @@ -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, @@ -154,12 +175,12 @@ Generator.prototype.convertFile = function(content, _input) { if (_output == "README.html") _output = "index.html"; var output = path.join(this.options.output, _output); var basePath = path.relative(path.dirname(output), this.options.output) || "."; - + // Bug fix for issue #493 which would occur when relative-links are 2-level or more deep in win32 if (process.platform === 'win32') { basePath = basePath.replace(/\\/g, '/'); } - + return this.prepareFile(content, _input) .then(function(page) { // Index page in search diff --git a/theme/templates/ebook/glossary.html b/theme/templates/ebook/glossary.html index 8076c4d..ce10c63 100644 --- a/theme/templates/ebook/glossary.html +++ b/theme/templates/ebook/glossary.html @@ -1,4 +1,4 @@ -{% extends "./layout.html" %} +{% extends "./page.html" %} {% block title %}Glossary | {{ title }}{% endblock %} diff --git a/theme/templates/ebook/page.html b/theme/templates/ebook/page.html index 9ce7c1b..3af7970 100644 --- a/theme/templates/ebook/page.html +++ b/theme/templates/ebook/page.html @@ -3,14 +3,17 @@ {% block title %}{{ progress.current.title }} | {{ title }}{% endblock %} {% block style %} -<link rel="stylesheet" href="{{ staticBase }}/print.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 }}/print.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 %} {% block content %} diff --git a/theme/templates/ebook/summary.html b/theme/templates/ebook/summary.html index dfbba2c..ab4b78f 100644 --- a/theme/templates/ebook/summary.html +++ b/theme/templates/ebook/summary.html @@ -1,18 +1,7 @@ -{% extends "./layout.html" %} +{% extends "./page.html" %} {% block title %}Table of Contents | {{ title }}{% endblock %} -{% block style %} -<link rel="stylesheet" href="{{ staticBase }}/print.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 %} -{% endblock %} - {% macro articles(_articles) %} {% for item in _articles %} {% set externalLink = item.path|isExternalLink %} diff --git a/theme/templates/book/glossary.html b/theme/templates/website/glossary.html index 4d9683f..4d9683f 100644 --- a/theme/templates/book/glossary.html +++ b/theme/templates/website/glossary.html diff --git a/theme/templates/book/includes/exercise.html b/theme/templates/website/includes/exercise.html index 42b500f..42b500f 100644 --- a/theme/templates/book/includes/exercise.html +++ b/theme/templates/website/includes/exercise.html diff --git a/theme/templates/book/includes/font-settings.html b/theme/templates/website/includes/font-settings.html index 5fa1f3e..5fa1f3e 100644 --- a/theme/templates/book/includes/font-settings.html +++ b/theme/templates/website/includes/font-settings.html diff --git a/theme/templates/book/includes/header.html b/theme/templates/website/includes/header.html index ef2de60..ef2de60 100644 --- a/theme/templates/book/includes/header.html +++ b/theme/templates/website/includes/header.html diff --git a/theme/templates/book/includes/quiz.html b/theme/templates/website/includes/quiz.html index 425fa39..425fa39 100644 --- a/theme/templates/book/includes/quiz.html +++ b/theme/templates/website/includes/quiz.html diff --git a/theme/templates/book/includes/summary.html b/theme/templates/website/includes/summary.html index 3fff7fe..3fff7fe 100644 --- a/theme/templates/book/includes/summary.html +++ b/theme/templates/website/includes/summary.html diff --git a/theme/templates/book/langs.html b/theme/templates/website/langs.html index 49878ae..7b47fc5 100755 --- a/theme/templates/book/langs.html +++ b/theme/templates/website/langs.html @@ -1,4 +1,4 @@ -{% extends "../layout.html" %} +{% extends "./layout.html" %} {% block title %}{{ title }}{% endblock %} diff --git a/theme/templates/layout.html b/theme/templates/website/layout.html index 5dc7c5e..5dc7c5e 100755..100644 --- a/theme/templates/layout.html +++ b/theme/templates/website/layout.html diff --git a/theme/templates/book/page.html b/theme/templates/website/page.html index d1379a2..91f2162 100644 --- a/theme/templates/book/page.html +++ b/theme/templates/website/page.html @@ -1,4 +1,4 @@ -{% extends "../layout.html" %} +{% extends "./layout.html" %} {% block head %} {% parent %} @@ -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 %} |