diff options
author | Samy Pessé <samypesse@gmail.com> | 2015-10-06 13:35:04 +0200 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2015-10-06 13:35:04 +0200 |
commit | 22e0c1fb54f1ffb632e7c155978929fa185b932c (patch) | |
tree | aa397f02d65e358980720624d29ec863587df354 | |
parent | ba65e3c020faa46eead7376c73af29e5e5839d8b (diff) | |
download | gitbook-22e0c1fb54f1ffb632e7c155978929fa185b932c.zip gitbook-22e0c1fb54f1ffb632e7c155978929fa185b932c.tar.gz gitbook-22e0c1fb54f1ffb632e7c155978929fa185b932c.tar.bz2 |
Fix css being used for pdf footer and header
-rwxr-xr-x | bin/gitbook.js | 6 | ||||
-rw-r--r-- | lib/generators/ebook.js | 116 | ||||
-rwxr-xr-x | theme/assets/print.css | 1 |
3 files changed, 61 insertions, 62 deletions
diff --git a/bin/gitbook.js b/bin/gitbook.js index 07d1da5..5f47420 100755 --- a/bin/gitbook.js +++ b/bin/gitbook.js @@ -2,6 +2,6 @@ var color = require('bash-color'); -console.log(color.red("You need to install 'gitbook-cli' to have access to the gitbook command anywhere on your system.")); -console.log(color.red("If you've installed this package globally, you need to uninstall it.")); -console.log(color.red(">> Run 'npm uninstall -g gitbook' then 'npm install -g gitbook-cli'")); +console.log(color.red('You need to install "gitbook-cli" to have access to the gitbook command anywhere on your system.')); +console.log(color.red('If you\'ve installed this package globally, you need to uninstall it.')); +console.log(color.red('>> Run "npm uninstall -g gitbook" then "npm install -g gitbook-cli"')); 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); }); diff --git a/theme/assets/print.css b/theme/assets/print.css deleted file mode 100755 index e658449..0000000 --- a/theme/assets/print.css +++ /dev/null @@ -1 +0,0 @@ -.page .anchor:focus,.page a:active,.page a:hover{outline:0}.page,.page hr{overflow:hidden}.page dl dt,.page strong,.page table th{font-weight:700}.page.page-glossary>h1,.page.page-toc>h1{text-align:center}.link-inherit,.link-inherit:focus,.link-inherit:hover{color:inherit}.pdf-footer,.pdf-header{margin-top:20px;color:#aaa}.hidden{display:none}body{font-family:sans-serif}.pdf-footer{padding-top:10px;border-top:1px solid #eee}.pdf-footer .footer-pages-count{float:right}.pdf-header{padding-bottom:10px;border-bottom:1px solid #eee}.page ol,.page td,.page th,.page ul{padding:0}.page hr,.page img{border:0}.page{-ms-text-size-adjust:100%;-webkit-text-size-adjust:100%;color:#000;line-height:1.6;word-wrap:break-word;display:block}.page pre,.page pre code{word-wrap:normal}.page>:first-child{margin-top:0!important}.page>:last-child{margin-bottom:0!important}.page a{background:0 0;color:#4183c4;text-decoration:none}.page h1{margin:.67em 0}.page hr{-moz-box-sizing:content-box;box-sizing:content-box}.page code,.page pre{direction:ltr;font-family:Consolas,"Liberation Mono",Menlo,Courier,monospace;font-size:12px}.page *{-moz-box-sizing:border-box;box-sizing:border-box}.page a:active,.page a:focus,.page a:hover{text-decoration:underline}.page hr:after,.page hr:before{display:table;content:" "}.page hr:after{clear:both}.page blockquote{margin:0}.page h1,.page h2{padding-bottom:.3em}.page ol ol{list-style-type:lower-roman}.page dd{margin-left:0}.page .markdown-body>:first-child{margin-top:0!important}.page .markdown-body>:last-child{margin-bottom:0!important}.page .anchor{position:absolute;top:0;bottom:0;left:0;display:block;padding-right:6px;padding-left:30px;margin-left:-30px}.page h1,.page h2,.page h3,.page h4,.page h5,.page h6{position:relative;margin-top:1em;margin-bottom:16px;font-weight:700;line-height:1.4}.page h1{font-size:2.25em;line-height:1.2}.page h2{font-size:1.75em;line-height:1.225}.page h3{font-size:1.5em;line-height:1.43}.page h4{font-size:1.25em}.page dl dt,.page h5,.page h6{font-size:1em}.page h6{color:#777}.page blockquote,.page dl,.page ol,.page p,.page pre,.page table,.page ul{margin-top:0;margin-bottom:16px}.page hr{background:#e7e7e7;height:4px;padding:0;margin:16px 0}.page ol,.page ul{padding-left:2em}.page ol ol,.page ol ul,.page ul ul{margin-top:0;margin-bottom:0}.page dl{padding:0}.page dl dt{padding:0;margin-top:16px;font-style:italic}.page .section>h1,.page .section>h2,.page .section>h3,.page blockquote>:first-child{margin-top:0}.page dl dd{padding:0 16px;margin-bottom:16px}.page blockquote{padding:0 15px;color:#777;border-left:4px solid #ddd}.page blockquote>:last-child{margin-bottom:0}.page table{border-collapse:collapse;border-spacing:0;display:block;width:100%;overflow:auto}.page table td,.page table th{padding:6px 13px;border:1px solid #ddd}.page table tr{background-color:#fff;border-top:1px solid #ccc}.page table tr:nth-child(2n){background-color:#f8f8f8}.page img{max-width:100%;-moz-box-sizing:border-box;box-sizing:border-box}.page code{padding:.2em 0;margin:0;font-size:85%;background-color:#f7f7f7;border-radius:3px}.page code:after,.page code:before{letter-spacing:-.2em;content:"\00a0"}.page pre>code{padding:0;margin:0;font-size:100%;white-space:pre;background:0 0;border:0}.page .highlight pre,.page pre{padding:16px;overflow:auto;font-size:85%;line-height:1.45;background-color:#f7f7f7;border:none;border-radius:3px}.page pre code,.page.page-toc>ol{margin:0;padding:0}.page pre code{display:inline;max-width:initial;overflow:initial;line-height:inherit;background-color:transparent;border:0}.page pre code:after,.page pre code:before{content:normal}.page .highlight{background:#fff}.page blockquote,.page code,.page figure,.page img,.page pre,.page table,.page tr{page-break-inside:avoid}.page h2,.page h3,.page p{orphans:3;widows:3}.page h1,.page h2,.page h3,.page h4,.page h5{page-break-after:avoid}.page .book-chapter{display:none}.page.page-toc li{list-style:none}.page.page-toc li .inner{display:block;border-bottom:1px dotted #eee;margin-bottom:4px}.page.page-toc li .inner a,.page.page-toc li .inner span{padding-right:5px;display:inline-block;border-bottom:1px solid #fff;margin-bottom:-1px}.page.page-toc li .inner span.page{float:right;padding-left:5px}.page.page-toc li ol{margin:0;padding:0 0 0 2em}.page.page-glossary .glossary{margin-bottom:40px}.page.page-glossary .glossary h2 a,.page.page-glossary .glossary h2 a:hover{color:inherit;text-decoration:none}.page.page-glossary .glossary .glossary-index{list-style:none;margin:0;padding:0}.page.page-glossary .glossary .glossary-index li{display:inline;margin:0 8px;white-space:nowrap}body.dir-rtl .page.page-toc li .inner .page{float:left}body.dir-rtl .page.page-toc li ol{margin:0;padding:0 2em 0 0}
\ No newline at end of file |