diff options
Diffstat (limited to 'lib/output/ebook')
-rw-r--r-- | lib/output/ebook/getConvertOptions.js | 73 | ||||
-rw-r--r-- | lib/output/ebook/getCoverPath.js | 30 | ||||
-rw-r--r-- | lib/output/ebook/getPDFTemplate.js | 41 | ||||
-rw-r--r-- | lib/output/ebook/index.js | 9 | ||||
-rw-r--r-- | lib/output/ebook/onFinish.js | 91 | ||||
-rw-r--r-- | lib/output/ebook/onPage.js | 24 | ||||
-rw-r--r-- | lib/output/ebook/options.js | 17 |
7 files changed, 0 insertions, 285 deletions
diff --git a/lib/output/ebook/getConvertOptions.js b/lib/output/ebook/getConvertOptions.js deleted file mode 100644 index bc80493..0000000 --- a/lib/output/ebook/getConvertOptions.js +++ /dev/null @@ -1,73 +0,0 @@ -var extend = require('extend'); - -var Promise = require('../../utils/promise'); -var getPDFTemplate = require('./getPDFTemplate'); -var getCoverPath = require('./getCoverPath'); - -/** - Generate options for ebook-convert - - @param {Output} - @return {Promise<Object>} -*/ -function getConvertOptions(output) { - var options = output.getOptions(); - var format = options.get('format'); - - var book = output.getBook(); - var config = book.getConfig(); - - return Promise() - .then(function() { - var coverPath = getCoverPath(output); - var options = { - '--cover': coverPath, - '--title': config.getValue('title'), - '--comments': config.getValue('description'), - '--isbn': config.getValue('isbn'), - '--authors': config.getValue('author'), - '--language': book.getLanguage() || config.getValue('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 \')]', - '--max-levels': '1', - '--no-chapters-in-toc': true, - '--breadth-first': true, - '--dont-split-on-page-breaks': format === 'epub'? true : undefined - }; - - if (format !== 'pdf') { - return options; - } - - return Promise.all([ - getPDFTemplate(output, 'header'), - getPDFTemplate(output, 'footer') - ]) - .spread(function(headerTpl, footerTpl) { - var pdfOptions = config.getValue('pdf').toJS(); - - return options = 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-sans-family': String(pdfOptions.fontFamily), - '--pdf-header-template': headerTpl, - '--pdf-footer-template': footerTpl - }); - }); - }); -} - - -module.exports = getConvertOptions; diff --git a/lib/output/ebook/getCoverPath.js b/lib/output/ebook/getCoverPath.js deleted file mode 100644 index ab6b579..0000000 --- a/lib/output/ebook/getCoverPath.js +++ /dev/null @@ -1,30 +0,0 @@ -var path = require('path'); -var fs = require('../../utils/fs'); - -/** - Resolve path to cover file to use - - @param {Output} - @return {String} -*/ -function getCoverPath(output) { - var outputRoot = output.getRoot(); - var book = output.getBook(); - var config = book.getConfig(); - var coverName = config.getValue('cover', 'cover.jpg'); - - // Resolve to absolute - var cover = fs.pickFile(outputRoot, coverName); - if (cover) { - return cover; - } - - // Multilingual? try parent folder - if (book.isLanguageBook()) { - cover = fs.pickFile(path.join(outputRoot, '..'), coverName); - } - - return cover; -} - -module.exports = getCoverPath; diff --git a/lib/output/ebook/getPDFTemplate.js b/lib/output/ebook/getPDFTemplate.js deleted file mode 100644 index b767daf..0000000 --- a/lib/output/ebook/getPDFTemplate.js +++ /dev/null @@ -1,41 +0,0 @@ -var juice = require('juice'); - -var WebsiteGenerator = require('../website'); -var JSONUtils = require('../../json'); -var Templating = require('../../templating'); -var Promise = require('../../utils/promise'); - - -/** - Generate PDF header/footer templates - - @param {Output} output - @param {String} type - @return {String} -*/ -function getPDFTemplate(output, type) { - var filePath = 'pdf_' + type + '.html'; - var outputRoot = output.getRoot(); - var engine = WebsiteGenerator.createTemplateEngine(output, filePath); - - // Generate context - var context = JSONUtils.encodeOutput(output); - context.page = { - num: '_PAGENUM_', - title: '_SECTION_' - }; - - // Render the theme - return Templating.renderFile(engine, 'ebook/' + filePath, context) - - // Inline css and assets - .then(function(tplOut) { - return Promise.nfcall(juice.juiceResources, tplOut.getContent(), { - webResources: { - relativeTo: outputRoot - } - }); - }); -} - -module.exports = getPDFTemplate; diff --git a/lib/output/ebook/index.js b/lib/output/ebook/index.js deleted file mode 100644 index 786a10a..0000000 --- a/lib/output/ebook/index.js +++ /dev/null @@ -1,9 +0,0 @@ -var extend = require('extend'); -var WebsiteGenerator = require('../website'); - -module.exports = extend({}, WebsiteGenerator, { - name: 'ebook', - Options: require('./options'), - onPage: require('./onPage'), - onFinish: require('./onFinish') -}); diff --git a/lib/output/ebook/onFinish.js b/lib/output/ebook/onFinish.js deleted file mode 100644 index 7f21548..0000000 --- a/lib/output/ebook/onFinish.js +++ /dev/null @@ -1,91 +0,0 @@ -var path = require('path'); - -var WebsiteGenerator = require('../website'); -var JSONUtils = require('../../json'); -var Templating = require('../../templating'); -var Promise = require('../../utils/promise'); -var error = require('../../utils/error'); -var command = require('../../utils/command'); -var writeFile = require('../helper/writeFile'); - -var getConvertOptions = require('./getConvertOptions'); -var SUMMARY_FILE = 'SUMMARY.html'; - -/** - Write the SUMMARY.html - - @param {Output} - @return {Output} -*/ -function writeSummary(output) { - var options = output.getOptions(); - var prefix = options.get('prefix'); - - var filePath = SUMMARY_FILE; - var engine = WebsiteGenerator.createTemplateEngine(output, filePath); - var context = JSONUtils.encodeOutput(output); - - // Render the theme - return Templating.renderFile(engine, prefix + '/summary.html', context) - - // Write it to the disk - .then(function(tplOut) { - return writeFile(output, filePath, tplOut.getContent()); - }); -} - -/** - Generate the ebook file as "index.pdf" - - @param {Output} - @return {Output} -*/ -function runEbookConvert(output) { - var logger = output.getLogger(); - var options = output.getOptions(); - var format = options.get('format'); - var outputFolder = output.getRoot(); - - if (!format) { - return Promise(output); - } - - return getConvertOptions(output) - .then(function(options) { - var cmd = [ - 'ebook-convert', - path.resolve(outputFolder, SUMMARY_FILE), - path.resolve(outputFolder, 'index.' + format), - command.optionsToShellArgs(options) - ].join(' '); - - return command.exec(cmd) - .progress(function(data) { - logger.debug(data); - }) - .fail(function(err) { - if (err.code == 127) { - throw error.RequireInstallError({ - cmd: 'ebook-convert', - install: 'Install it from Calibre: https://calibre-ebook.com' - }); - } - - throw error.EbookError(err); - }); - }) - .thenResolve(output); -} - -/** - Finish the generation, generates the SUMMARY.html - - @param {Output} - @return {Output} -*/ -function onFinish(output) { - return writeSummary(output) - .then(runEbookConvert); -} - -module.exports = onFinish; diff --git a/lib/output/ebook/onPage.js b/lib/output/ebook/onPage.js deleted file mode 100644 index b7b9b42..0000000 --- a/lib/output/ebook/onPage.js +++ /dev/null @@ -1,24 +0,0 @@ -var WebsiteGenerator = require('../website'); -var Modifiers = require('../modifiers'); - -/** - Write a page for ebook output - - @param {Output} output - @param {Output} -*/ -function onPage(output, page) { - var options = output.getOptions(); - - // Inline assets - return Modifiers.modifyHTML(page, [ - Modifiers.inlineAssets(options.get('root'), page.getFile().getPath()) - ]) - - // Write page using website generator - .then(function(resultPage) { - return WebsiteGenerator.onPage(output, resultPage); - }); -} - -module.exports = onPage; diff --git a/lib/output/ebook/options.js b/lib/output/ebook/options.js deleted file mode 100644 index ea7b8b4..0000000 --- a/lib/output/ebook/options.js +++ /dev/null @@ -1,17 +0,0 @@ -var Immutable = require('immutable'); - -var Options = Immutable.Record({ - // Root folder for the output - root: String(), - - // Prefix for generation - prefix: String('ebook'), - - // Format to generate using ebook-convert - format: String(), - - // Force use of absolute urls ("index.html" instead of "/") - directoryIndex: Boolean(false) -}); - -module.exports = Options; |