mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 07:35:16 +00:00
Compare commits
35 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 62c99759c1 | |||
| 6951c21d19 | |||
| 3a8289483e | |||
| 4079de9587 | |||
| b86d171082 | |||
| 959b272e65 | |||
| 684440e2d1 | |||
| 4740cd3b06 | |||
| b3131d99d2 | |||
| b0fd2a67ea | |||
| 7c83869869 | |||
| 57d5c23eaf | |||
| 8d92b74e61 | |||
| 4e2cda99cc | |||
| dd250e0339 | |||
| 741b158631 | |||
| 843889303e | |||
| 4ad2b040b4 | |||
| f5916b5c59 | |||
| d9da4e9a08 | |||
| 1d0f6370ad | |||
| 12a7a4c4cf | |||
| e4127d961e | |||
| 8e97655040 | |||
| 9b61b87873 | |||
| 4a99e37b2f | |||
| 752b5e9b7c | |||
| b318f2fe94 | |||
| 01c46030b6 | |||
| 9803b05d8a | |||
| 1337858fe6 | |||
| 925b9e88ad | |||
| 7305011a8b | |||
| 489f23f74e | |||
| 370799ac55 |
@@ -32,5 +32,9 @@ Translators
|
||||
- Ryan O'Mullan (@RyanOM)
|
||||
- Spanish
|
||||
- Ryan O'Mullan (@RyanOM)
|
||||
- Simplifiled Chinese
|
||||
- Hu Hao (@howiehu)
|
||||
- Traditional Chinese
|
||||
- Hu Hao (@howiehu)
|
||||
- French
|
||||
- Samy Pessé (@SamyPesse)
|
||||
|
||||
@@ -1,5 +1,11 @@
|
||||
# Release notes
|
||||
|
||||
## 2.0.0-alpha.7
|
||||
- Fix display of glossary in ebook formats
|
||||
- Add default footer and header to pdf
|
||||
- Fix generation of json format compatible with 1.x.x
|
||||
- Add Simplifiled Chinese and Traditional Chinese translations
|
||||
|
||||
## 2.0.0-alpha.6
|
||||
- Add es and pt translations
|
||||
- Fix replacement of glossary terms
|
||||
|
||||
+12
-7
@@ -10,6 +10,7 @@ var fs = require("./utils/fs");
|
||||
var parseNavigation = require("./utils/navigation");
|
||||
var parseProgress = require("./utils/progress");
|
||||
var pageUtil = require("./utils/page");
|
||||
var batch = require("./utils/batch");
|
||||
var links = require("./utils/links");
|
||||
var logger = require("./utils/logger");
|
||||
|
||||
@@ -224,9 +225,11 @@ Book.prototype.generate = function(generator) {
|
||||
|
||||
// Finally let's generate content
|
||||
.then(function() {
|
||||
return _.reduce(ops["content"] || [], function(prev, file) {
|
||||
var nFiles = (ops["content"] || []).length;
|
||||
return _.reduce(ops["content"] || [], function(prev, file, i) {
|
||||
return prev.then(function() {
|
||||
that.log.debug.ln("converting", file);
|
||||
var p = ((i*100)/nFiles).toFixed(0)+"%";
|
||||
that.log.info.ln("processing", file, p);
|
||||
return Q(generator.convertFile(file));
|
||||
});
|
||||
}, Q());
|
||||
@@ -261,9 +264,6 @@ Book.prototype.generateMultiLingual = function(generator) {
|
||||
return book.generate(that.options.generator);
|
||||
});
|
||||
}, Q());
|
||||
})
|
||||
.then(function() {
|
||||
return generator.langsIndex(that.langs);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -517,7 +517,7 @@ Book.prototype.parsePage = function(filename, options) {
|
||||
page.content = content;
|
||||
|
||||
that.log.debug.ln("use file parser", filetype.name, "for", filename);
|
||||
return filetype.parser.page(page.content);
|
||||
return filetype.page(page.content);
|
||||
})
|
||||
|
||||
// Post process sections
|
||||
@@ -573,7 +573,7 @@ Book.prototype.findFile = function(filename) {
|
||||
.then(function(exists) {
|
||||
if (!exists) return null;
|
||||
return {
|
||||
parser: parsers.get(ext).parser,
|
||||
parser: parsers.get(ext),
|
||||
path: filepath
|
||||
};
|
||||
})
|
||||
@@ -651,6 +651,11 @@ Book.prototype.isSubBook = function() {
|
||||
return !!this.parent;
|
||||
};
|
||||
|
||||
// Test if the file is the entry point
|
||||
Book.prototype.isEntryPoint = function(fp) {
|
||||
return fp == this.readmeFile;
|
||||
};
|
||||
|
||||
// Resolve a path in book
|
||||
Book.prototype.resolve = function(p) {
|
||||
return path.resolve(this.root, p);
|
||||
|
||||
@@ -5,6 +5,7 @@ var semver = require('semver');
|
||||
|
||||
var pkg = require('../package.json');
|
||||
var fs = require("./utils/fs");
|
||||
var i18n = require("./utils/i18n");
|
||||
|
||||
// Default plugins added to each books
|
||||
var defaultsPlugins = [];
|
||||
@@ -124,7 +125,7 @@ Configuration.prototype.getStructure = function(name) {
|
||||
|
||||
// Return normalized language
|
||||
Configuration.prototype.normalizeLanguage = function() {
|
||||
return _.first(this.options.language.split("-")).toLowerCase();
|
||||
return i18n.normalizeLanguage(this.options.language);
|
||||
};
|
||||
|
||||
|
||||
@@ -219,8 +220,8 @@ Configuration.DEFAULT = {
|
||||
"margin": {
|
||||
"right": 62,
|
||||
"left": 62,
|
||||
"top": 36,
|
||||
"bottom": 36
|
||||
"top": 56,
|
||||
"bottom": 56
|
||||
},
|
||||
|
||||
//Header HTML template. Available variables: _PAGENUM_, _TITLE_, _AUTHOR_ and _SECTION_.
|
||||
|
||||
@@ -70,11 +70,6 @@ BaseGenerator.prototype.copyCover = function() {
|
||||
});
|
||||
};
|
||||
|
||||
// Generate the langs index
|
||||
BaseGenerator.prototype.langsIndex = function(langs) {
|
||||
return Q.reject(new Error("Langs index is not supported in this generator"));
|
||||
};
|
||||
|
||||
// At teh end of the generation
|
||||
BaseGenerator.prototype.finish = function() {
|
||||
return Q.reject(new Error("Could not finish generation"));
|
||||
|
||||
+7
-11
@@ -41,18 +41,14 @@ Generator.prototype.writeSummary = function() {
|
||||
return this._writeTemplate(this.templates["summary"], {}, path.join(this.options.output, "SUMMARY.html"));
|
||||
};
|
||||
|
||||
|
||||
Generator.prototype.langsIndex = function(langs) {
|
||||
return Q();
|
||||
};
|
||||
|
||||
Generator.prototype.finish = function() {
|
||||
var that = this;
|
||||
|
||||
return BaseGenerator.prototype.finish.apply(this)
|
||||
.then(function() {
|
||||
return that.writeSummary();
|
||||
})
|
||||
return Q()
|
||||
.then(this.copyAssets)
|
||||
.then(this.copyCover)
|
||||
.then(this.writeGlossary)
|
||||
.then(this.writeSummary)
|
||||
.then(function() {
|
||||
if (!that.ebookFormat) return Q();
|
||||
|
||||
@@ -92,8 +88,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),
|
||||
"--pdf-footer-template": String(pdfOptions.footerTemplate)
|
||||
"--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>"
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
+14
-10
@@ -14,7 +14,6 @@ util.inherits(Generator, BaseGenerator);
|
||||
|
||||
// Ignore some methods
|
||||
Generator.prototype.transferFile = function(input) { };
|
||||
Generator.prototype.finish = function() { };
|
||||
|
||||
// Convert an input file
|
||||
Generator.prototype.convertFile = function(input) {
|
||||
@@ -37,21 +36,26 @@ Generator.prototype.convertFile = function(input) {
|
||||
});
|
||||
};
|
||||
|
||||
// Generate languages index
|
||||
// Contains the first languages readme and langs infos
|
||||
Generator.prototype.langsIndex = function(langs) {
|
||||
// Finish generation
|
||||
Generator.prototype.finish = function() {
|
||||
return this.writeReadme();
|
||||
};
|
||||
|
||||
// Write README.json
|
||||
Generator.prototype.writeReadme = function() {
|
||||
var that = this;
|
||||
|
||||
if (langs.length == 0) return Q.reject("Need at least one language");
|
||||
|
||||
var mainLang = _.first(langs).lang;
|
||||
var readme = links.changeExtension(that.book.readmeFile, ".json");
|
||||
var mainlang, langs;
|
||||
|
||||
return Q()
|
||||
.then(function() {
|
||||
langs = that.book.langs;
|
||||
mainLang = langs.length > 0? _.first(langs).lang : null;
|
||||
|
||||
readme = links.changeExtension(that.book.readmeFile, ".json");
|
||||
|
||||
// Read readme from main language
|
||||
return fs.readFile(
|
||||
path.join(that.options.output, mainLang, readme)
|
||||
mainLang? path.join(that.options.output, mainLang, readme) : path.join(that.options.output, readme)
|
||||
);
|
||||
})
|
||||
.then(function(content) {
|
||||
|
||||
+12
-18
@@ -12,6 +12,7 @@ var fs = require("../utils/fs");
|
||||
var BaseGenerator = require("../generator");
|
||||
var links = require("../utils/links");
|
||||
var pageUtil = require("../utils/page");
|
||||
var i18n = require("../utils/i18n");
|
||||
|
||||
var pkg = require("../../package.json");
|
||||
|
||||
@@ -74,20 +75,12 @@ Generator.prototype.prepareTemplates = function() {
|
||||
Generator.prototype.prepareTemplateEngine = function() {
|
||||
var that = this;
|
||||
|
||||
return fs.readdir(path.resolve(__dirname, "../../theme/i18n"))
|
||||
.then(function(locales) {
|
||||
return Q()
|
||||
.then(function() {
|
||||
var language = that.book.config.normalizeLanguage();
|
||||
|
||||
locales = _.chain(locales)
|
||||
.map(function(local) {
|
||||
local = path.basename(local, ".json");
|
||||
return [local, require("../../theme/i18n/"+local)];
|
||||
})
|
||||
.object()
|
||||
.value();
|
||||
|
||||
if (!_.contains(_.keys(locales), language) && language != "en") {
|
||||
that.book.log.warn.ln("Language '"+language+"' is not available as a layout locales (en, "+_.keys(locales).join(", ")+")");
|
||||
if (!i18n.getByLanguage(language) && language != "en") {
|
||||
that.book.log.warn.ln("Language '"+language+"' is not available as a layout locales (en, "+i18n.getLanguages().join(", ")+")");
|
||||
}
|
||||
|
||||
var folders = _.chain(that.templates)
|
||||
@@ -114,7 +107,7 @@ Generator.prototype.prepareTemplateEngine = function() {
|
||||
that.env.addExtension('FilterExtension', new FilterExtension(that.env));
|
||||
that.env.addExtension('I18nExtension', new I18nExtension({
|
||||
env: that.env,
|
||||
translations: locales,
|
||||
translations: i18n.getLocales(),
|
||||
locale: "language"
|
||||
}));
|
||||
});
|
||||
@@ -125,7 +118,8 @@ Generator.prototype.finish = function() {
|
||||
return this.copyAssets()
|
||||
.then(this.copyCover)
|
||||
.then(this.writeGlossary)
|
||||
.then(this.writeSearchIndex);
|
||||
.then(this.writeSearchIndex)
|
||||
.then(this.writeLangsIndex)
|
||||
};
|
||||
|
||||
// Convert an input file
|
||||
@@ -148,7 +142,7 @@ Generator.prototype.convertFile = function(input) {
|
||||
var basePath = path.relative(path.dirname(output), that.options.output) || ".";
|
||||
if (process.platform === 'win32') basePath = basePath.replace(/\\/g, '/');
|
||||
|
||||
that.book.log.info.ln("write parsed file", page.path, "to", relativeOutput);
|
||||
that.book.log.debug.ln("write parsed file", page.path, "to", relativeOutput);
|
||||
|
||||
return that._writeTemplate(that.templates["page"], {
|
||||
progress: page.progress,
|
||||
@@ -163,11 +157,11 @@ Generator.prototype.convertFile = function(input) {
|
||||
};
|
||||
|
||||
// Write the index for langs
|
||||
Generator.prototype.langsIndex = function(langs) {
|
||||
Generator.prototype.writeLangsIndex = function() {
|
||||
var that = this;
|
||||
|
||||
if (!this.book.langs.length) return Q();
|
||||
return this._writeTemplate(this.templates["langs"], {
|
||||
langs: langs
|
||||
langs: this.book.langs
|
||||
}, path.join(this.options.output, "index.html"));
|
||||
};
|
||||
|
||||
|
||||
+42
-19
@@ -6,6 +6,7 @@ var nunjucks = require("nunjucks");
|
||||
var git = require("./utils/git");
|
||||
var stringUtils = require("./utils/string");
|
||||
var fs = require("./utils/fs");
|
||||
var batch = require("./utils/batch");
|
||||
var pkg = require("../package.json");
|
||||
|
||||
|
||||
@@ -87,18 +88,21 @@ TemplateEngine.prototype.processBlock = function(blk) {
|
||||
if (_.isString(blk)) blk = { body: blk };
|
||||
|
||||
blk = _.defaults(blk, {
|
||||
parse: false
|
||||
parse: false,
|
||||
post: undefined
|
||||
});
|
||||
blk.id = _.uniqueId("blk");
|
||||
|
||||
var toAdd = (!blk.parse) || (blk.post != undefined);
|
||||
|
||||
// Add to global map
|
||||
if (toAdd) this.blocks[blk.id] = blk;
|
||||
|
||||
//Parsable block, just return it
|
||||
if (blk.parse) {
|
||||
return blk.body;
|
||||
}
|
||||
|
||||
// Add to global map
|
||||
this.blocks[blk.id] = blk;
|
||||
|
||||
// Return it as a macro
|
||||
return "%+%"+blk.id+"%+%";
|
||||
};
|
||||
@@ -114,9 +118,6 @@ TemplateEngine.prototype.replaceBlocks = function(content) {
|
||||
|
||||
var body = blk.body;
|
||||
|
||||
// Remove it from map
|
||||
delete that.blocks[key];
|
||||
|
||||
return body;
|
||||
});
|
||||
};
|
||||
@@ -239,21 +240,25 @@ TemplateEngine.prototype.addBlock = function(name, block) {
|
||||
var args = Array.prototype.slice.call(arguments, 1);
|
||||
var callback = args.pop();
|
||||
|
||||
// Extract blocks body
|
||||
var _blocks = _.chain(block.blocks)
|
||||
.reverse()
|
||||
.map(function(blockName){
|
||||
return {
|
||||
name: blockName,
|
||||
body: args.pop()()
|
||||
};
|
||||
})
|
||||
.reverse()
|
||||
.value();
|
||||
// Extract blocks
|
||||
var blocks = args
|
||||
.concat([])
|
||||
.slice(-block.blocks.length);
|
||||
|
||||
// Eliminate blocks from list
|
||||
if (block.blocks.length > 0) args = args.slice(0, -block.blocks.length);
|
||||
|
||||
// Extract main body and kwargs
|
||||
var body = args.pop();
|
||||
var kwargs = args.pop() || {};
|
||||
|
||||
// Extract blocks body
|
||||
var _blocks = _.map(block.blocks, function(blockName, i){
|
||||
return {
|
||||
name: blockName,
|
||||
body: blocks[i]()
|
||||
};
|
||||
});
|
||||
|
||||
var func = that.bindContext(block.process);
|
||||
|
||||
@@ -363,8 +368,26 @@ TemplateEngine.prototype.renderPage = function(page) {
|
||||
|
||||
// Post process content
|
||||
TemplateEngine.prototype.postProcess = function(content) {
|
||||
var that = this;
|
||||
|
||||
return Q(content)
|
||||
.then(this.replaceBlocks);
|
||||
.then(that.replaceBlocks)
|
||||
.then(function(_content) {
|
||||
return batch.execEach(that.blocks, {
|
||||
max: 20,
|
||||
fn: function(blk, blkId) {
|
||||
return Q()
|
||||
.then(function() {
|
||||
if (!blk.post) return Q();
|
||||
return blk.post();
|
||||
})
|
||||
.then(function() {
|
||||
delete that.blocks[blkId];
|
||||
});
|
||||
}
|
||||
})
|
||||
.thenResolve(_content);
|
||||
});
|
||||
};
|
||||
|
||||
module.exports = TemplateEngine;
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
var Q = require("q");
|
||||
var _ = require("lodash");
|
||||
|
||||
// Execute a method for all element
|
||||
function execEach(items, options) {
|
||||
if (_.size(items) == 0) return Q();
|
||||
var concurrents = 0, d = Q.defer(), pending = [];
|
||||
|
||||
options = _.defaults(options || {}, {
|
||||
max: 100,
|
||||
fn: function(item) {}
|
||||
});
|
||||
|
||||
|
||||
function startItem(item, i) {
|
||||
if (concurrents >= options.max) {
|
||||
pending.push([item, i]);
|
||||
return;
|
||||
}
|
||||
|
||||
concurrents++;
|
||||
Q()
|
||||
.then(function() {
|
||||
return options.fn(item, i);
|
||||
})
|
||||
.then(function() {
|
||||
concurrents--;
|
||||
|
||||
// Next pending
|
||||
var next = pending.shift();
|
||||
|
||||
if (concurrents == 0 && !next) {
|
||||
d.resolve();
|
||||
} else if (next) {
|
||||
startItem.apply(null, next);
|
||||
}
|
||||
})
|
||||
.fail(function(err) {
|
||||
pending = [];
|
||||
d.reject(err);
|
||||
})
|
||||
}
|
||||
|
||||
_.each(items, startItem);
|
||||
|
||||
return d.promise;
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
execEach: execEach
|
||||
};
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
var _ = require("lodash");
|
||||
var path = require("path");
|
||||
var fs = require("fs");
|
||||
|
||||
var I18N_PATH = path.resolve(__dirname, "../../theme/i18n/")
|
||||
|
||||
var getLocales = _.memoize(function() {
|
||||
var locales = fs.readdirSync(I18N_PATH);
|
||||
return _.chain(locales)
|
||||
.map(function(local) {
|
||||
local = path.basename(local, ".json");
|
||||
return [local, _.extend(require(path.join(I18N_PATH, local)), {
|
||||
id: local
|
||||
})];
|
||||
})
|
||||
.object()
|
||||
.value();
|
||||
});
|
||||
|
||||
var getLanguages = function() {
|
||||
return _.keys(getLocales());
|
||||
};
|
||||
|
||||
var getByLanguage = function(lang) {
|
||||
lang = normalizeLanguage(lang);
|
||||
var locales = getLocales();
|
||||
return locales[lang];
|
||||
};
|
||||
|
||||
var compareLocales = function(lang, locale) {
|
||||
var langMain = _.first(lang.split("-"));
|
||||
var langSecond = _.last(lang.split("-"));
|
||||
|
||||
var localeMain = _.first(locale.split("-"));
|
||||
var localeSecond = _.last(locale.split("-"));
|
||||
|
||||
if (locale == lang) return 100;
|
||||
if (localeMain == langMain) return 50;
|
||||
if (localeSecond == langSecond) return 20;
|
||||
return 0;
|
||||
};
|
||||
|
||||
var normalizeLanguage = _.memoize(function(lang) {
|
||||
var locales = getLocales();
|
||||
var language = _.chain(locales)
|
||||
.values()
|
||||
.map(function(locale) {
|
||||
locale = locale.id;
|
||||
|
||||
return {
|
||||
locale: locale,
|
||||
score: compareLocales(lang, locale)
|
||||
}
|
||||
})
|
||||
.filter(function(lang) {
|
||||
return lang.score > 0;
|
||||
})
|
||||
.sortBy("score")
|
||||
.pluck("locale")
|
||||
.last()
|
||||
.value();
|
||||
return language || lang;
|
||||
});
|
||||
|
||||
module.exports = {
|
||||
getLocales: getLocales,
|
||||
getLanguages: getLanguages,
|
||||
getByLanguage: getByLanguage,
|
||||
normalizeLanguage: normalizeLanguage
|
||||
};
|
||||
+5
-1
@@ -22,7 +22,11 @@ var convertSVG = function(source, dest, options) {
|
||||
if (error.code == 127) error = new Error("Need to install 'svgexport' using 'npm install svgexport -g'");
|
||||
return d.reject(error);
|
||||
}
|
||||
d.resolve();
|
||||
if (fs.existsSync(dest)) {
|
||||
d.resolve();
|
||||
} else {
|
||||
d.reject(new Error("Error converting "+source));
|
||||
}
|
||||
});
|
||||
|
||||
return d.promise;
|
||||
|
||||
+33
-24
@@ -4,10 +4,12 @@ var path = require('path');
|
||||
var cheerio = require('cheerio');
|
||||
var domSerializer = require('dom-serializer');
|
||||
var request = require('request');
|
||||
var crc = require("crc");
|
||||
|
||||
var links = require('./links');
|
||||
var imgUtils = require('./images');
|
||||
var fs = require('./fs');
|
||||
var batch = require('./batch');
|
||||
|
||||
// Render a cheerio dom as html
|
||||
var renderDom = function($, dom, options) {
|
||||
@@ -111,6 +113,7 @@ function normalizeHtml(src, options) {
|
||||
$("img").each(function() {
|
||||
var origin = undefined;
|
||||
var src = $(this).attr("src");
|
||||
if (!src) return;
|
||||
var isExternal = links.isExternal(src);
|
||||
|
||||
// Transform as relative to the bases
|
||||
@@ -123,7 +126,7 @@ function normalizeHtml(src, options) {
|
||||
// If image is external and ebook, then downlaod the images
|
||||
if (isExternal) {
|
||||
origin = src;
|
||||
src = "/"+fs.getUniqueFilename(outputRoot, path.basename(src));
|
||||
src = "/"+crc.crc32(origin).toString(16)+path.extname(origin);
|
||||
src = links.toAbsolute(src, options.base, options.output);
|
||||
isExternal = false;
|
||||
}
|
||||
@@ -181,6 +184,7 @@ function normalizeHtml(src, options) {
|
||||
|
||||
$("a").each(function() {
|
||||
var href = $(this).attr("href");
|
||||
if (!href) return;
|
||||
|
||||
if (links.isRelative(href)) {
|
||||
var absolutePath = path.join(options.base, href);
|
||||
@@ -211,7 +215,7 @@ function normalizeHtml(src, options) {
|
||||
term.files = term.files || [];
|
||||
term.files.push(options.navigation[options.input]);
|
||||
}
|
||||
return "<a href='"+links.toAbsolute("GLOSSARY.html", options.base, options.output)+"#"+term.id+"' class='glossary-term' title='"+term.description+"'>"+match+"</a>";
|
||||
return "<a href='"+links.toAbsolute("/GLOSSARY.html", options.base, options.output)+"#"+term.id+"' class='glossary-term' title='"+_.escape(term.description)+"'>"+match+"</a>";
|
||||
});
|
||||
});
|
||||
});
|
||||
@@ -226,34 +230,39 @@ function normalizeHtml(src, options) {
|
||||
function convertImages(images, options) {
|
||||
if (!options.convertImages) return Q();
|
||||
|
||||
var downloaded = [];
|
||||
options.book.log.debug.ln("convert ", images.length, "images to png");
|
||||
|
||||
return _.reduce(images, function(prev, image) {
|
||||
var imgin = path.resolve(options.book.options.output, image.source);
|
||||
return batch.execEach(images, {
|
||||
max: 100,
|
||||
fn: function(image) {
|
||||
var imgin = path.resolve(options.book.options.output, image.source);
|
||||
|
||||
return prev
|
||||
return Q()
|
||||
|
||||
// Write image if need to be download
|
||||
.then(function() {
|
||||
if (!image.origin) return;
|
||||
options.book.log.debug("download image", image.origin, "...");
|
||||
return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin)));
|
||||
})
|
||||
// Write image if need to be download
|
||||
.then(function() {
|
||||
if (!image.origin && !_.contains(downloaded, image.origin)) return;
|
||||
options.book.log.debug("download image", image.origin, "...");
|
||||
downloaded.push(image.origin);
|
||||
return options.book.log.debug.promise(fs.writeStream(imgin, request(image.origin)));
|
||||
})
|
||||
|
||||
// Write svg if content
|
||||
.then(function() {
|
||||
if (!image.content) return;
|
||||
return fs.writeFile(imgin, image.content);
|
||||
})
|
||||
// Write svg if content
|
||||
.then(function() {
|
||||
if (!image.content) return;
|
||||
return fs.writeFile(imgin, image.content);
|
||||
})
|
||||
|
||||
// Convert
|
||||
.then(function(){
|
||||
if (!image.dest) return;
|
||||
var imgout = path.resolve(options.book.options.output, image.dest);
|
||||
options.book.log.debug("convert image", image.source, "to", image.dest, "...");
|
||||
return options.book.log.debug.promise(imgUtils.convertSVG(imgin, imgout));
|
||||
});
|
||||
}, Q())
|
||||
// Convert
|
||||
.then(function() {
|
||||
if (!image.dest) return;
|
||||
var imgout = path.resolve(options.book.options.output, image.dest);
|
||||
options.book.log.debug("convert image", image.source, "to", image.dest, "...");
|
||||
return options.book.log.debug.promise(imgUtils.convertSVG(imgin, imgout));
|
||||
});
|
||||
}
|
||||
})
|
||||
.then(function() {
|
||||
options.book.log.debug.ok(images.length+" images converted with success");
|
||||
});
|
||||
|
||||
+4
-4
@@ -1,18 +1,18 @@
|
||||
{
|
||||
"name": "gitbook",
|
||||
"version": "2.0.0-alpha.6",
|
||||
"version": "2.0.0-alpha.8",
|
||||
"homepage": "https://www.gitbook.com",
|
||||
"description": "Library and cmd utility to generate GitBooks",
|
||||
"main": "lib/index.js",
|
||||
"dependencies": {
|
||||
"q": "1.0.1",
|
||||
"lunr": "0.5.7",
|
||||
"lodash": "2.4.1",
|
||||
"lodash": "3.2.0",
|
||||
"graceful-fs": "3.0.5",
|
||||
"resolve": "0.6.3",
|
||||
"fs-extra": "0.16.3",
|
||||
"fstream-ignore": "1.0.2",
|
||||
"gitbook-parsers": "0.3.1",
|
||||
"gitbook-parsers": "0.4.1",
|
||||
"nunjucks": "git+https://github.com/SamyPesse/nunjucks.git#4019d1b7379372336b86ce1b0bf84352a2029747",
|
||||
"nunjucks-autoescape": "0.1.0",
|
||||
"nunjucks-filter": "0.1.0",
|
||||
@@ -30,7 +30,7 @@
|
||||
"URIjs": "1.14.1",
|
||||
"request": "2.51.0",
|
||||
"npm": "2.4.1",
|
||||
"dom-serializer": "git+https://github.com/SamyPesse/dom-serializer.git#57ed9a2c3dfa964022ce7d71859c558ba7721785"
|
||||
"dom-serializer": "0.1.0"
|
||||
},
|
||||
"devDependencies": {
|
||||
"mocha": "1.18.2",
|
||||
|
||||
+15
-19
@@ -1,6 +1,7 @@
|
||||
var path = require('path');
|
||||
var _ = require('lodash');
|
||||
var assert = require('assert');
|
||||
var cheerio = require('cheerio');
|
||||
|
||||
var fs = require("fs");
|
||||
var fsUtil = require("../lib/utils/fs");
|
||||
@@ -15,26 +16,21 @@ describe('eBook Generator', function () {
|
||||
|
||||
it('should correctly convert svg images to png', function(done) {
|
||||
testGeneration(books[4], "ebook", function(output) {
|
||||
var readmeContent = fs.readFileSync(path.join(output, "index.html"), {encoding: "utf8"});
|
||||
var pageContent = fs.readFileSync(path.join(output, "sub/PAGE.html"), {encoding: "utf8"});
|
||||
// Check that all images exists
|
||||
_.each([
|
||||
"index.html",
|
||||
"sub/PAGE.html"
|
||||
], function(pageName) {
|
||||
var pageFile = path.join(output, pageName);
|
||||
var pageFolder = path.dirname(pageFile);
|
||||
var pageContent = fs.readFileSync(pageFile, {encoding: "utf8"});
|
||||
var $ = cheerio.load(pageContent);
|
||||
|
||||
// Remote image
|
||||
assert(pageContent.indexOf('src="../Tux.png"') >= 0);
|
||||
assert(fs.existsSync(path.join(output, "Tux.png")));
|
||||
|
||||
assert(fs.existsSync(path.join(output, "test.png")));
|
||||
assert(fs.existsSync(path.join(output, "NewTux.png")));
|
||||
|
||||
assert(!fs.existsSync(path.join(output, "test_0.png")));
|
||||
assert(!fs.existsSync(path.join(output, "sub/test.png")));
|
||||
assert(!fs.existsSync(path.join(output, "sub/NewTux.png")));
|
||||
|
||||
assert(pageContent.indexOf('src="../test.png"') >= 0);
|
||||
assert(pageContent.indexOf('src="../NewTux.png"') >= 0);
|
||||
assert(pageContent.indexOf('<svg') < 0);
|
||||
|
||||
assert(readmeContent.indexOf('src="test.png"') >= 0);
|
||||
assert(readmeContent.indexOf('src="NewTux.png"') >= 0);
|
||||
$("img").each(function() {
|
||||
var src = $(this).attr("src");
|
||||
assert(fs.existsSync(path.resolve(pageFolder, src)), src+" not found for page "+pageName);
|
||||
})
|
||||
});
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
Vendored
+2
@@ -4,3 +4,5 @@ This is a relative link [test](../intro.md).
|
||||
|
||||

|
||||
|
||||
This is a glossary link.
|
||||
|
||||
|
||||
Vendored
+4
@@ -5,3 +5,7 @@ A description
|
||||

|
||||

|
||||

|
||||
|
||||
# Test with youtube videos that have the same filename:
|
||||

|
||||

|
||||
|
||||
Vendored
+2
-2
@@ -8,8 +8,8 @@
|
||||
## Inline svg
|
||||
|
||||
{% html %}
|
||||
<svg width="400" height="110">
|
||||
<rect width="300" height="100" style="fill:rgb(0,0,255);stroke-width:3;stroke:rgb(0,0,0)">
|
||||
<svg xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M97.008198003228,6.103238498249268A97.2,97.2 0 0,1 87.9491894996971,41.385747140125076L54.289623147961166,25.546757493904366A60,60 0 0,0 59.88160370569629,3.7674311717588074Z"></path>
|
||||
</svg>
|
||||
{% endhtml %}
|
||||
|
||||
|
||||
@@ -19,4 +19,17 @@ describe('Glossary Generation', function () {
|
||||
assert($a.text() == "description");
|
||||
}, done);
|
||||
});
|
||||
|
||||
it('should correctly replace glossary terms in sub pages', function(done) {
|
||||
testGeneration(books[1], "website", function(output) {
|
||||
var content = fs.readFileSync(path.join(output, "sub/test1.html"), { encoding: "utf8" });
|
||||
var $ = cheerio.load(content);
|
||||
|
||||
var $body = $(".page-inner");
|
||||
var $a = $("a[href='../GLOSSARY.html#test']");
|
||||
assert($a.length == 1);
|
||||
assert($a.text() == "test");
|
||||
assert($a.attr("title") == "a test text");
|
||||
}, done);
|
||||
});
|
||||
});
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ describe('JSON generator', function () {
|
||||
|
||||
it('should correctly generate a book to json with sub folders', function(done) {
|
||||
testGeneration(books[1], "json", function(output) {
|
||||
assert(!fs.existsSync(path.join(output, "README.json")));
|
||||
assert(fs.existsSync(path.join(output, "README.json")));
|
||||
assert(fs.existsSync(path.join(output, "intro.json")));
|
||||
assert(fs.existsSync(path.join(output, "sub/test1.json")));
|
||||
|
||||
|
||||
File diff suppressed because one or more lines are too long
+3
-1
@@ -14,5 +14,7 @@
|
||||
"SHARE_ON": "Auf __platform__ teilen",
|
||||
"FONTSETTINGS_WHITE": "Hell",
|
||||
"FONTSETTINGS_SEPIA": "Sepia",
|
||||
"FONTSETTINGS_NIGHT": "Nacht"
|
||||
"FONTSETTINGS_NIGHT": "Nacht",
|
||||
"FONTSETTINGS_SANS": "Sans",
|
||||
"FONTSETTINGS_SERIF": "Serif"
|
||||
}
|
||||
+3
-1
@@ -14,5 +14,7 @@
|
||||
"SHARE_ON": "Comparte en __platform__",
|
||||
"FONTSETTINGS_WHITE": "Claro",
|
||||
"FONTSETTINGS_SEPIA": "Sépia",
|
||||
"FONTSETTINGS_NIGHT": "Noche"
|
||||
"FONTSETTINGS_NIGHT": "Noche",
|
||||
"FONTSETTINGS_SANS": "Sans",
|
||||
"FONTSETTINGS_SERIF": "Serif"
|
||||
}
|
||||
|
||||
+3
-1
@@ -14,5 +14,7 @@
|
||||
"SHARE_ON": "Partager sur __platform__",
|
||||
"FONTSETTINGS_WHITE": "Clair",
|
||||
"FONTSETTINGS_SEPIA": "Sépia",
|
||||
"FONTSETTINGS_NIGHT": "Nuit"
|
||||
"FONTSETTINGS_NIGHT": "Nuit",
|
||||
"FONTSETTINGS_SANS": "Sans",
|
||||
"FONTSETTINGS_SERIF": "Serif"
|
||||
}
|
||||
+3
-1
@@ -14,5 +14,7 @@
|
||||
"SHARE_ON": "Condividi su __platform__",
|
||||
"FONTSETTINGS_WHITE": "Bianco",
|
||||
"FONTSETTINGS_SEPIA": "Seppia",
|
||||
"FONTSETTINGS_NIGHT": "Notte"
|
||||
"FONTSETTINGS_NIGHT": "Notte",
|
||||
"FONTSETTINGS_SANS": "Sans",
|
||||
"FONTSETTINGS_SERIF": "Serif"
|
||||
}
|
||||
+3
-1
@@ -14,5 +14,7 @@
|
||||
"SHARE_ON": "Del på __platform__",
|
||||
"FONTSETTINGS_WHITE": "Lys",
|
||||
"FONTSETTINGS_SEPIA": "Sepia",
|
||||
"FONTSETTINGS_NIGHT": "Mørk"
|
||||
"FONTSETTINGS_NIGHT": "Mørk",
|
||||
"FONTSETTINGS_SANS": "Sans",
|
||||
"FONTSETTINGS_SERIF": "Serif"
|
||||
}
|
||||
|
||||
+3
-1
@@ -14,5 +14,7 @@
|
||||
"SHARE_ON": "Compartilhar no __platform__",
|
||||
"FONTSETTINGS_WHITE": "Claro",
|
||||
"FONTSETTINGS_SEPIA": "Sépia",
|
||||
"FONTSETTINGS_NIGHT": "Noite"
|
||||
"FONTSETTINGS_NIGHT": "Noite",
|
||||
"FONTSETTINGS_SANS": "Sans",
|
||||
"FONTSETTINGS_SERIF": "Serif"
|
||||
}
|
||||
|
||||
+3
-1
@@ -14,5 +14,7 @@
|
||||
"SHARE_ON": "Поделиться в __platform__",
|
||||
"FONTSETTINGS_WHITE": "Светлый",
|
||||
"FONTSETTINGS_SEPIA": "Сепия",
|
||||
"FONTSETTINGS_NIGHT": "Тёмный"
|
||||
"FONTSETTINGS_NIGHT": "Тёмный",
|
||||
"FONTSETTINGS_SANS": "Sans",
|
||||
"FONTSETTINGS_SERIF": "Serif"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"LANGS_CHOOSE": "选择一种语言",
|
||||
"GLOSSARY": "术语表",
|
||||
"GLOSSARY_INDEX": "索引",
|
||||
"GLOSSARY_OPEN": "术语表",
|
||||
"GITBOOK_LINK": "本书使用 GitBook 发布",
|
||||
"SUMMARY": "目录",
|
||||
"SUMMARY_INTRODUCTION": "介绍",
|
||||
"SUMMARY_TOGGLE": "目录",
|
||||
"SEARCH_TOGGLE": "搜索",
|
||||
"SEARCH_PLACEHOLDER": "输入并搜索",
|
||||
"FONTSETTINGS_TOGGLE": "字体设置",
|
||||
"SHARE_TOGGLE": "分享",
|
||||
"SHARE_ON": "分享到 __platform__",
|
||||
"FONTSETTINGS_WHITE": "白色",
|
||||
"FONTSETTINGS_SEPIA": "棕褐色",
|
||||
"FONTSETTINGS_NIGHT": "夜间",
|
||||
"FONTSETTINGS_SANS": "无衬线体",
|
||||
"FONTSETTINGS_SERIF": "衬线体"
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
{
|
||||
"LANGS_CHOOSE": "選擇一種語言",
|
||||
"GLOSSARY": "術語表",
|
||||
"GLOSSARY_INDEX": "索引",
|
||||
"GLOSSARY_OPEN": "術語表",
|
||||
"GITBOOK_LINK": "本書使用 GitBook 釋出",
|
||||
"SUMMARY": "目錄",
|
||||
"SUMMARY_INTRODUCTION": "介紹",
|
||||
"SUMMARY_TOGGLE": "目錄",
|
||||
"SEARCH_TOGGLE": "搜尋",
|
||||
"SEARCH_PLACEHOLDER": "輸入並搜尋",
|
||||
"FONTSETTINGS_TOGGLE": "字型設定",
|
||||
"SHARE_TOGGLE": "分享",
|
||||
"SHARE_ON": "分享到 __platform__",
|
||||
"FONTSETTINGS_WHITE": "白色",
|
||||
"FONTSETTINGS_SEPIA": "棕褐色",
|
||||
"FONTSETTINGS_NIGHT": "夜間",
|
||||
"FONTSETTINGS_SANS": "無襯線體",
|
||||
"FONTSETTINGS_SERIF": "襯線體"
|
||||
}
|
||||
@@ -5,52 +5,33 @@
|
||||
|
||||
.page {
|
||||
&.page-toc {
|
||||
ol {
|
||||
margin: 0px;
|
||||
.glossary {
|
||||
margin-bottom: 40px;
|
||||
|
||||
h2 {
|
||||
a, a:hover {
|
||||
color: inherit;
|
||||
text-decoration: none;
|
||||
}
|
||||
}
|
||||
|
||||
.glossary-index {
|
||||
list-style: none;
|
||||
margin: 0px;
|
||||
padding: 0px;
|
||||
|
||||
li {
|
||||
display: inline;
|
||||
margin: 0px 8px;
|
||||
white-space: nowrap;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.book-chapter {
|
||||
display: none;
|
||||
}
|
||||
|
||||
.exercise, .quiz {
|
||||
margin: 1cm 0cm;
|
||||
border: 2px solid #ddd;
|
||||
|
||||
.exercise-header {
|
||||
padding: 0.1cm 0.3cm;
|
||||
background: #f5f5f5;
|
||||
border-bottom: 1px solid #ddd;
|
||||
font-weight: bold;
|
||||
page-break-inside: avoid;
|
||||
}
|
||||
|
||||
.exercise-inner {
|
||||
padding: 0.15cm 0.3cm;
|
||||
|
||||
p:last-child {
|
||||
margin: 0px;
|
||||
}
|
||||
}
|
||||
|
||||
hr {
|
||||
height: 2px;
|
||||
}
|
||||
|
||||
.question {
|
||||
margin-top: 0.1cm;
|
||||
border-top: 1px solid #ddd;
|
||||
|
||||
.question-base {
|
||||
|
||||
}
|
||||
|
||||
.question-solution {
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -4,12 +4,18 @@
|
||||
|
||||
{% block content %}
|
||||
<div class="page page-toc">
|
||||
<h1>Glossary</h1>
|
||||
{% for item in glossaryIndex %}
|
||||
<section class="normal glossary" id="{{ item.id }}">
|
||||
<h2><a href="#{{ item.id }}">{{ item.name }}</a></h2>
|
||||
<p>{{ item.description }}</p>
|
||||
</section>
|
||||
{% endfor %}
|
||||
<h1 class="book-chapter book-chapter-1">{% i18n "GLOSSARY" %}Glossary{% endi18n %}</h1>
|
||||
<h1>{% i18n "GLOSSARY" %}Glossary{% endi18n %}</h1>
|
||||
{% for item in glossary %}
|
||||
<section class="normal glossary" id="{{ item.id }}">
|
||||
<h2><a href="#{{ item.id }}">{{ item.name }}</a></h2>
|
||||
<p>{{ item.description|safe }}</p>
|
||||
<ul class="glossary-index">
|
||||
{% for file in item.files %}
|
||||
<li><a href="{{ basePath }}/{{ file.path|contentLink }}"><span class="level">{{ file.level }}.</span> {{ file.title }}</a></li>
|
||||
{% endfor %}
|
||||
</ul>
|
||||
</section>
|
||||
{% endfor %}
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
@@ -6,8 +6,7 @@
|
||||
{% for item in glossary %}
|
||||
<section class="normal glossary" id="{{ item.id }}">
|
||||
<h2><a href="#{{ item.id }}">{{ item.name }}</a></h2>
|
||||
<p>{{ item.description }}</p>
|
||||
<h4>{% i18n "GLOSSARY_INDEX" %}Index{% endi18n %}</h4>
|
||||
<p>{{ item.description|safe }}</p>
|
||||
<ul class="glossary-index">
|
||||
{% for file in item.files %}
|
||||
<li><a href="{{ basePath }}/{{ file.path|contentLink }}"><span class="level">{{ file.level }}.</span> {{ file.title }}</a></li>
|
||||
|
||||
Reference in New Issue
Block a user