diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/configuration.js | 19 | ||||
-rw-r--r-- | lib/generators/ebook.js | 36 |
2 files changed, 36 insertions, 19 deletions
diff --git a/lib/configuration.js b/lib/configuration.js index 563fcef..7488fae 100644 --- a/lib/configuration.js +++ b/lib/configuration.js @@ -277,7 +277,6 @@ Configuration.DEFAULT = { // Margin (in pts) // Note: 72 pts equals 1 inch -<<<<<<< HEAD 'margin': { 'right': 62, 'left': 62, @@ -286,24 +285,10 @@ Configuration.DEFAULT = { }, // Header HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_. - 'headerTemplate': '', + 'headerTemplate': null, // Footer HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_. - 'footerTemplate': '' -======= - "margin": { - "right": 62, - "left": 62, - "top": 62, - "bottom": 62 - }, - - //Header HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_. - "headerTemplate": fs.readFileSync(path.resolve(__dirname, '../theme/templates/ebook/header.html'), { encoding: 'utf-8' }), - - //Footer HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_. - "footerTemplate": fs.readFileSync(path.resolve(__dirname, '../theme/templates/ebook/footer.html'), { encoding: 'utf-8' }) ->>>>>>> Add css to footer/header for pdf + 'footerTemplate': null } }; diff --git a/lib/generators/ebook.js b/lib/generators/ebook.js index e6a33d3..075fca5 100644 --- a/lib/generators/ebook.js +++ b/lib/generators/ebook.js @@ -2,6 +2,7 @@ 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"); @@ -41,6 +42,37 @@ Generator.prototype.writeSummary = function() { 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'); + + // Default template from theme + if (!tpl && fs.existsSync(defaultTpl)) { + tpl = fs.readFileSync(defaultTpl, { encoding: 'utf-8' }); + } + + // Inline CSS using juice + var stylesheets = []; + + // From theme + if (fs.existsSync(defaultCSS)) { + stylesheets.push(fs.readFileSync(defaultCSS, { encoding: 'utf-8' })); + } + + // Custom PDF style + if (this.styles.pdf) { + stylesheets.push(fs.readFileSync(this.book.resolve(this.styles.pdf), { encoding: 'utf-8' })); + } + + tpl = juice(tpl, { + extraCss: stylesheets.concat('/n') + }); + + return tpl; +}; + Generator.prototype.finish = function() { var that = this; @@ -90,8 +122,8 @@ Generator.prototype.finish = function() { "--pdf-mono-font-size": String(pdfOptions.fontSize), "--paper-size": String(pdfOptions.paperSize), "--pdf-page-numbers": Boolean(pdfOptions.pageNumbers), - "--pdf-header-template": String(pdfOptions.headerTemplate) || "<p class='header'><span>"+that.options.title+"</span></p>", - "--pdf-footer-template": String(pdfOptions.footerTemplate) || "<p class='footer'><span>_SECTION_</span> <span style='float:right;'>_PAGENUM_</span></p>" + "--pdf-header-template": that.getPDFTemplate('header'), + "--pdf-footer-template": that.getPDFTemplate('footer') }); } else if (that.ebookFormat == "epub") { _.extend(_options, { |