summaryrefslogtreecommitdiffstats
path: root/lib/generators/ebook.js
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-10-06 13:35:04 +0200
committerSamy Pessé <samypesse@gmail.com>2015-10-06 13:35:04 +0200
commit22e0c1fb54f1ffb632e7c155978929fa185b932c (patch)
treeaa397f02d65e358980720624d29ec863587df354 /lib/generators/ebook.js
parentba65e3c020faa46eead7376c73af29e5e5839d8b (diff)
downloadgitbook-22e0c1fb54f1ffb632e7c155978929fa185b932c.zip
gitbook-22e0c1fb54f1ffb632e7c155978929fa185b932c.tar.gz
gitbook-22e0c1fb54f1ffb632e7c155978929fa185b932c.tar.bz2
Fix css being used for pdf footer and header
Diffstat (limited to 'lib/generators/ebook.js')
-rw-r--r--lib/generators/ebook.js116
1 files changed, 58 insertions, 58 deletions
diff --git a/lib/generators/ebook.js b/lib/generators/ebook.js
index 075fca5..96775b1 100644
--- a/lib/generators/ebook.js
+++ b/lib/generators/ebook.js
@@ -1,13 +1,13 @@
-var util = require("util");
-var path = require("path");
-var Q = require("q");
-var _ = require("lodash");
-var juice = require("juice");
-var exec = require("child_process").exec;
+var util = require('util');
+var path = require('path');
+var Q = require('q');
+var _ = require('lodash');
+var juice = require('juice');
+var exec = require('child_process').exec;
-var fs = require("../utils/fs");
-var stringUtils = require("../utils/string");
-var BaseGenerator = require("./website");
+var fs = require('../utils/fs');
+var stringUtils = require('../utils/string');
+var BaseGenerator = require('./website');
var Generator = function(book, format) {
BaseGenerator.apply(this, arguments);
@@ -16,10 +16,10 @@ var Generator = function(book, format) {
this.ebookFormat = format;
// Resources namespace
- this.namespace = "ebook";
+ this.namespace = 'ebook';
// Styles to use
- this.styles = _.compact(["print", "ebook", this.ebookFormat]);
+ this.styles = _.compact(['print', 'ebook', this.ebookFormat]);
// Convert images (svg -> png)
this.convertImages = true;
@@ -27,9 +27,9 @@ var Generator = function(book, format) {
util.inherits(Generator, BaseGenerator);
Generator.prototype.prepareTemplates = function() {
- this.templates.page = this.book.plugins.template("ebook:page") || path.resolve(this.options.theme, "templates/ebook/page.html");
- this.templates.summary = this.book.plugins.template("ebook:summary") || path.resolve(this.options.theme, "templates/ebook/summary.html");
- this.templates.glossary = this.book.plugins.template("ebook:glossary") || path.resolve(this.options.theme, "templates/ebook/glossary.html");
+ this.templates.page = this.book.plugins.template('ebook:page') || path.resolve(this.options.theme, 'templates/ebook/page.html');
+ this.templates.summary = this.book.plugins.template('ebook:summary') || path.resolve(this.options.theme, 'templates/ebook/summary.html');
+ this.templates.glossary = this.book.plugins.template('ebook:glossary') || path.resolve(this.options.theme, 'templates/ebook/glossary.html');
return Q();
};
@@ -38,15 +38,15 @@ Generator.prototype.prepareTemplates = function() {
Generator.prototype.writeSummary = function() {
var that = this;
- that.book.log.info.ln("write SUMMARY.html");
- return this._writeTemplate(this.templates.summary, {}, path.join(this.options.output, "SUMMARY.html"));
+ that.book.log.info.ln('write SUMMARY.html');
+ return this._writeTemplate(this.templates.summary, {}, path.join(this.options.output, 'SUMMARY.html'));
};
// Return template for footer/header with inlined css
Generator.prototype.getPDFTemplate = function(id) {
var tpl = this.options.pdf[id+'Template'];
var defaultTpl = path.resolve(this.options.theme, 'templates/ebook/'+id+'.html');
- var defaultCSS = path.resolve(this.options.theme, 'assets/print.css');
+ var defaultCSS = path.resolve(this.options.theme, 'assets/pdf.css');
// Default template from theme
if (!tpl && fs.existsSync(defaultTpl)) {
@@ -84,70 +84,70 @@ Generator.prototype.finish = function() {
.then(function() {
if (!that.ebookFormat) return Q();
- if (!that.options.cover && fs.existsSync(path.join(that.options.output, "cover.jpg"))) {
- that.options.cover = path.join(that.options.output, "cover.jpg");
+ if (!that.options.cover && fs.existsSync(path.join(that.options.output, 'cover.jpg'))) {
+ that.options.cover = path.join(that.options.output, 'cover.jpg');
}
var d = Q.defer();
var _options = {
- "--cover": that.options.cover,
- "--title": that.options.title,
- "--comments": that.options.description,
- "--isbn": that.options.isbn,
- "--authors": that.options.author,
- "--language": that.options.language,
- "--book-producer": "GitBook",
- "--publisher": "GitBook",
- "--chapter": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter ')]",
- "--level1-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-1 ')]",
- "--level2-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-2 ')]",
- "--level3-toc": "descendant-or-self::*[contains(concat(' ', normalize-space(@class), ' '), ' book-chapter-3 ')]",
- "--no-chapters-in-toc": true,
- "--max-levels": "1",
- "--breadth-first": true
+ '--cover': that.options.cover,
+ '--title': that.options.title,
+ '--comments': that.options.description,
+ '--isbn': that.options.isbn,
+ '--authors': that.options.author,
+ '--language': that.options.language,
+ '--book-producer': 'GitBook',
+ '--publisher': 'GitBook',
+ '--chapter': 'descendant-or-self::*[contains(concat(\' \', normalize-space(@class), \' \'), \' book-chapter \')]',
+ '--level1-toc': 'descendant-or-self::*[contains(concat(\' \', normalize-space(@class), \' \'), \' book-chapter-1 \')]',
+ '--level2-toc': 'descendant-or-self::*[contains(concat(\' \', normalize-space(@class), \' \'), \' book-chapter-2 \')]',
+ '--level3-toc': 'descendant-or-self::*[contains(concat(\' \', normalize-space(@class), \' \'), \' book-chapter-3 \')]',
+ '--no-chapters-in-toc': true,
+ '--max-levels': '1',
+ '--breadth-first': true
};
- if (that.ebookFormat == "pdf") {
+ if (that.ebookFormat == 'pdf') {
var pdfOptions = that.options.pdf;
_.extend(_options, {
- "--chapter-mark": String(pdfOptions.chapterMark),
- "--page-breaks-before": String(pdfOptions.pageBreaksBefore),
- "--margin-left": String(pdfOptions.margin.left),
- "--margin-right": String(pdfOptions.margin.right),
- "--margin-top": String(pdfOptions.margin.top),
- "--margin-bottom": String(pdfOptions.margin.bottom),
- "--pdf-default-font-size": String(pdfOptions.fontSize),
- "--pdf-mono-font-size": String(pdfOptions.fontSize),
- "--paper-size": String(pdfOptions.paperSize),
- "--pdf-page-numbers": Boolean(pdfOptions.pageNumbers),
- "--pdf-header-template": that.getPDFTemplate('header'),
- "--pdf-footer-template": that.getPDFTemplate('footer')
+ '--chapter-mark': String(pdfOptions.chapterMark),
+ '--page-breaks-before': String(pdfOptions.pageBreaksBefore),
+ '--margin-left': String(pdfOptions.margin.left),
+ '--margin-right': String(pdfOptions.margin.right),
+ '--margin-top': String(pdfOptions.margin.top),
+ '--margin-bottom': String(pdfOptions.margin.bottom),
+ '--pdf-default-font-size': String(pdfOptions.fontSize),
+ '--pdf-mono-font-size': String(pdfOptions.fontSize),
+ '--paper-size': String(pdfOptions.paperSize),
+ '--pdf-page-numbers': Boolean(pdfOptions.pageNumbers),
+ '--pdf-header-template': that.getPDFTemplate('header'),
+ '--pdf-footer-template': that.getPDFTemplate('footer')
});
- } else if (that.ebookFormat == "epub") {
+ } else if (that.ebookFormat == 'epub') {
_.extend(_options, {
- "--dont-split-on-page-breaks": true
+ '--dont-split-on-page-breaks': true
});
}
var command = [
- "ebook-convert",
- path.join(that.options.output, "SUMMARY.html"),
- path.join(that.options.output, "index."+that.ebookFormat),
+ 'ebook-convert',
+ path.join(that.options.output, 'SUMMARY.html'),
+ path.join(that.options.output, 'index.'+that.ebookFormat),
stringUtils.optionsToShellArgs(_options)
- ].join(" ");
+ ].join(' ');
- that.book.log.info("start conversion to", that.ebookFormat, "....");
+ that.book.log.info('start conversion to', that.ebookFormat, '....');
var child = exec(command, function (error, stdout) {
if (error) {
that.book.log.info.fail();
if (error.code == 127) {
- error.message = "Need to install ebook-convert from Calibre";
+ error.message = 'Need to install ebook-convert from Calibre';
} else {
- error.message = error.message + " "+stdout;
+ error.message = error.message + ' '+stdout;
}
return d.reject(error);
}
@@ -156,11 +156,11 @@ Generator.prototype.finish = function() {
d.resolve();
});
- child.stdout.on("data", function (data) {
+ child.stdout.on('data', function (data) {
that.book.log.debug(data);
});
- child.stderr.on("data", function (data) {
+ child.stderr.on('data', function (data) {
that.book.log.debug(data);
});