mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-26 12:18:01 +00:00
Compare commits
21 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f0c97756de | |||
| f14c57d4c2 | |||
| b6f60cc8ad | |||
| 170516d343 | |||
| c931e91bef | |||
| db9151ae36 | |||
| f2d86b6d69 | |||
| 534cdd091b | |||
| fdf4a48638 | |||
| 58a3c5634e | |||
| f0ddb6e89f | |||
| 2b408db7cb | |||
| 4e4bd23e2b | |||
| 62d0eb606e | |||
| 0e9beeae14 | |||
| 5e4dbdee24 | |||
| 9435dae6cd | |||
| 813210bf47 | |||
| c372dfc544 | |||
| ac77200683 | |||
| f5afbc90a4 |
@@ -55,3 +55,5 @@ Translators
|
||||
- Hong Nguyen (@nghong)
|
||||
- Hebrew
|
||||
- @a-moses
|
||||
- Ukrainian
|
||||
- @Karnaukhov
|
||||
|
||||
+14
@@ -2,6 +2,20 @@
|
||||
All notable changes to this project will be documented in this file.
|
||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## 2.4.3
|
||||
- Add ukrainian translation (`uk`)
|
||||
- Add `book.json` configuration for maximum size of search index
|
||||
- Improve reliability of summary parser
|
||||
|
||||
## 2.4.2
|
||||
- Default plugins should not be installed by `gitbook install`
|
||||
- Limit search index size to avoid crash during generation
|
||||
- Fix code highlighting for html without language specified
|
||||
- Fix warning message for gitbook version when building a multilingual book
|
||||
|
||||
## 2.4.1
|
||||
- Fix disabling of default plugins, ex: `-highlight`
|
||||
|
||||
## 2.4.0
|
||||
- Fix page being updated when user wants to open a link in a new tab
|
||||
- Plugins can now replaced default code highlighter
|
||||
|
||||
@@ -4,12 +4,13 @@ GitBook
|
||||
[](http://badge.fury.io/js/gitbook)
|
||||
[](https://travis-ci.org/GitbookIO/gitbook)
|
||||
[](https://ci.appveyor.com/project/GitBook/gitbook)
|
||||
[](https://slack.gitbook.com)
|
||||
|
||||
GitBook is a command line tool (and Node.js library) for building beautiful books using GitHub/Git and Markdown (or AsciiDoc). Here is an example: [Learn Javascript](https://www.gitbook.com/book/GitBookIO/javascript).
|
||||
|
||||
You can publish and host book easily online using [gitbook.com](https://www.gitbook.com), a desktop editor is [also available](https://www.gitbook.com/editor).
|
||||
|
||||
Stay updated by following [@GitBookIO](https://twitter.com/GitBookIO) on Twitter or [GitBook](https://www.facebook.com/gitbookcom) on Facebook.
|
||||
Check out the [GitBook Community Slack Channel](https://slack.gitbook.com), Stay updated by following [@GitBookIO](https://twitter.com/GitBookIO) on Twitter or [GitBook](https://www.facebook.com/gitbookcom) on Facebook.
|
||||
|
||||
Complete documentation is available at [help.gitbook.com](http://help.gitbook.com/).
|
||||
|
||||
|
||||
+16
-2
@@ -79,6 +79,8 @@ var Book = function(root, context, parent) {
|
||||
this.langsFile = null;
|
||||
|
||||
// Search Index
|
||||
this.searchIndexEnabled = true;
|
||||
this.searchIndexSize = 0;
|
||||
this.searchIndex = lunr(function () {
|
||||
this.ref("url");
|
||||
|
||||
@@ -738,13 +740,25 @@ Book.prototype.contentLink = function(link) {
|
||||
// Index a page into the search index
|
||||
Book.prototype.indexPage = function(page) {
|
||||
var nav = this.navigation[page.path];
|
||||
if (!nav) return;
|
||||
if (!nav || !this.searchIndexEnabled) return;
|
||||
|
||||
this.log.debug.ln("index page", page.path);
|
||||
|
||||
// Extract text from the page
|
||||
var text = pageUtil.extractText(page.sections);
|
||||
|
||||
// Limit size of index (to avoid #941)
|
||||
this.searchIndexSize = this.searchIndexSize + text.length;
|
||||
if (this.searchIndexSize > this.config.get('search.maxIndexSize')) {
|
||||
this.log.warn.ln("search index is too big, indexing is now disabled");
|
||||
this.searchIndexEnabled = false;
|
||||
return;
|
||||
}
|
||||
|
||||
this.searchIndex.add({
|
||||
url: this.contentLink(page.path),
|
||||
title: nav.title,
|
||||
body: pageUtil.extractText(page.sections),
|
||||
body: text
|
||||
});
|
||||
};
|
||||
|
||||
|
||||
+50
-17
@@ -7,10 +7,24 @@ var pkg = require("../package.json");
|
||||
var i18n = require("./utils/i18n");
|
||||
|
||||
// Default plugins added to each books
|
||||
var defaultsPlugins = ["highlight"];
|
||||
var DEFAULT_PLUGINS = ["highlight"];
|
||||
|
||||
// Check if a plugin is a default plugin
|
||||
// Plugin should be in the list
|
||||
// And version from book.json specified for this plugin should be satisfied
|
||||
function isDefaultPlugin(name, version) {
|
||||
if (!_.contains(DEFAULT_PLUGINS, name)) return false;
|
||||
|
||||
try {
|
||||
var pluginPkg = require('gitbook-plugin-'+name+'/package.json');
|
||||
return semver.satisfies(pluginPkg.version, version || '*');
|
||||
} catch(e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// Normalize a list of plugins to use
|
||||
function normalizePluginsList(plugins) {
|
||||
function normalizePluginsList(plugins, addDefaults) {
|
||||
// Normalize list to an array
|
||||
plugins = _.isString(plugins) ? plugins.split(",") : (plugins || []);
|
||||
|
||||
@@ -22,9 +36,12 @@ function normalizePluginsList(plugins) {
|
||||
if (plugin.name) return plugin;
|
||||
|
||||
var parts = plugin.split("@");
|
||||
var name = parts[0];
|
||||
var version = parts[1];
|
||||
return {
|
||||
"name": parts[0],
|
||||
"version": parts[1] // optional
|
||||
"name": name,
|
||||
"version": version, // optional
|
||||
"isDefault": isDefaultPlugin(name, version)
|
||||
};
|
||||
});
|
||||
|
||||
@@ -39,18 +56,27 @@ function normalizePluginsList(plugins) {
|
||||
.value();
|
||||
|
||||
// Merge with defaults
|
||||
plugins = _.chain(plugins)
|
||||
.concat(_.map(defaultsPlugins, function(plugin) {
|
||||
return { "name": plugin };
|
||||
}))
|
||||
.uniq()
|
||||
.value();
|
||||
if (addDefaults !== false) {
|
||||
_.each(DEFAULT_PLUGINS, function(plugin) {
|
||||
if (_.find(plugins, { name: plugin })) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Build final list
|
||||
plugins.push({
|
||||
"name": plugin,
|
||||
"isDefault": true
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// Remove plugin that start with '-'
|
||||
plugins = _.filter(plugins, function(plugin) {
|
||||
return !_.contains(toremove, plugin.name) && !(plugin.name.length > 0 && plugin.name[0] == "-");
|
||||
});
|
||||
|
||||
// Remove duplicates
|
||||
plugins = _.uniq(plugins, 'name');
|
||||
|
||||
return plugins;
|
||||
}
|
||||
|
||||
@@ -112,16 +138,18 @@ Configuration.prototype.load = function() {
|
||||
}
|
||||
})
|
||||
.then(function() {
|
||||
if (!semver.satisfies(pkg.version, that.options.gitbook)) {
|
||||
throw "GitBook version doesn't satisfy version required by the book: "+that.options.gitbook;
|
||||
}
|
||||
if (that.options.gitbook != "*" && !semver.satisfies(semver.inc(pkg.version, "patch"), that.options.gitbook)) {
|
||||
that.book.log.warn.ln("gitbook version specified in your book.json might be too strict for future patches, \""+(_.first(pkg.version.split("."))+".x.x")+"\" is more adequate");
|
||||
if (!that.book.isSubBook()) {
|
||||
if (!semver.satisfies(pkg.version, that.options.gitbook)) {
|
||||
throw new Error("GitBook version doesn't satisfy version required by the book: "+that.options.gitbook);
|
||||
}
|
||||
if (that.options.gitbook != "*" && !semver.satisfies(semver.inc(pkg.version, "patch"), that.options.gitbook)) {
|
||||
that.book.log.warn.ln("gitbook version specified in your book.json might be too strict for future patches, \""+(_.first(pkg.version.split("."))+".x.x")+"\" is more adequate");
|
||||
}
|
||||
}
|
||||
|
||||
that.options.output = path.resolve(that.options.output || that.book.resolve("_book"));
|
||||
that.options.plugins = normalizePluginsList(that.options.plugins);
|
||||
that.options.defaultsPlugins = normalizePluginsList(that.options.defaultsPlugins || "");
|
||||
that.options.defaultsPlugins = normalizePluginsList(that.options.defaultsPlugins || "", false);
|
||||
that.options.plugins = _.union(that.options.plugins, that.options.defaultsPlugins);
|
||||
that.options.plugins = _.uniq(that.options.plugins, "name");
|
||||
|
||||
@@ -173,6 +201,11 @@ Configuration.DEFAULT = {
|
||||
// version of gitbook to use
|
||||
"gitbook": "*",
|
||||
|
||||
// Search index
|
||||
"search": {
|
||||
"maxIndexSize": 1000000
|
||||
},
|
||||
|
||||
// Structure
|
||||
"structure": {
|
||||
"langs": "LANGS.md",
|
||||
|
||||
+2
-3
@@ -146,11 +146,10 @@ PluginsList.prototype.resources = function(namespace) {
|
||||
// Install plugins from a book
|
||||
PluginsList.prototype.install = function() {
|
||||
var that = this;
|
||||
var defaultsPlugins = _.pluck(that.book.options.defaultsPlugins);
|
||||
|
||||
// Remove defaults (no need to install)
|
||||
var plugins = _.filter(that.book.options.plugins, function(plugin) {
|
||||
return !_.contains(defaultsPlugins, plugin.name);
|
||||
var plugins = _.reject(that.book.options.plugins, {
|
||||
isDefault: true
|
||||
});
|
||||
|
||||
// Install plugins one by one
|
||||
|
||||
+4
-3
@@ -244,14 +244,15 @@ function normalizeHtml(src, options) {
|
||||
.value();
|
||||
|
||||
var source = $(this).text();
|
||||
var html = options.book.template.applyBlock("code", {
|
||||
var blk = options.book.template.applyBlock("code", {
|
||||
body: source,
|
||||
kwargs: {
|
||||
language: lang
|
||||
}
|
||||
}).body;
|
||||
});
|
||||
|
||||
$(this).html(html);
|
||||
if (blk.html === false) $(this).text(blk.body);
|
||||
else $(this).html(blk.body);
|
||||
});
|
||||
|
||||
// Replace glossary terms
|
||||
|
||||
+5
-5
@@ -1,20 +1,20 @@
|
||||
{
|
||||
"name": "gitbook",
|
||||
"version": "2.4.0",
|
||||
"version": "2.4.3",
|
||||
"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",
|
||||
"lunr": "0.5.12",
|
||||
"lodash": "3.10.1",
|
||||
"graceful-fs": "3.0.5",
|
||||
"resolve": "0.6.3",
|
||||
"fs-extra": "0.16.5",
|
||||
"fstream-ignore": "1.0.2",
|
||||
"gitbook-parsers": "0.8.2",
|
||||
"gitbook-plugin-highlight": "1.0.1",
|
||||
"nunjucks": "mozilla/nunjucks#dc89bf91611a2101731c2c06afcf5c32160b4dc9",
|
||||
"gitbook-parsers": "0.8.3",
|
||||
"gitbook-plugin-highlight": "1.0.3",
|
||||
"nunjucks": "2.1.0",
|
||||
"nunjucks-autoescape": "1.0.0",
|
||||
"nunjucks-filter": "1.0.0",
|
||||
"i18n": "0.5.0",
|
||||
|
||||
@@ -12,4 +12,5 @@ Block with a language
|
||||
test 2
|
||||
```
|
||||
|
||||
Inline code: `test 3`
|
||||
Inline code: `test 3`
|
||||
Inline code with html: `<test>`
|
||||
@@ -52,5 +52,14 @@ describe("Code Highlighting", function () {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it("should correctly replace highlighting for inline code with html tags", function() {
|
||||
PAGE.should.be.html({
|
||||
"code": {
|
||||
index: 3,
|
||||
text: "code_<test>_code"
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
+15
-1
@@ -192,7 +192,21 @@ describe("Plugins", function () {
|
||||
});
|
||||
});
|
||||
|
||||
it("should correctly extend template blocks with arguments", function() {
|
||||
it("should correctly extend template blocks with arguments (1)", function() {
|
||||
return testTpl("{% test5args \"a\" %}{% endtest5args %}")
|
||||
.then(function(content) {
|
||||
content.should.equal("test5atest5");
|
||||
});
|
||||
});
|
||||
|
||||
it("should correctly extend template blocks with arguments (2)", function() {
|
||||
return testTpl("{% test5args 'a', 'b' %}{% endtest5args %}")
|
||||
.then(function(content) {
|
||||
content.should.equal("test5a,btest5");
|
||||
});
|
||||
});
|
||||
|
||||
it("should correctly extend template blocks with arguments (3)", function() {
|
||||
return testTpl("{% test5args 'a', 'b', 'c' %}{% endtest5args %}")
|
||||
.then(function(content) {
|
||||
content.should.equal("test5a,b,ctest5");
|
||||
|
||||
@@ -4,7 +4,10 @@ module.exports = {
|
||||
process: function(blk) {
|
||||
var lang = blk.kwargs.language || "code";
|
||||
|
||||
return lang+"_"+blk.body+"_"+lang;
|
||||
return {
|
||||
body: lang+"_"+blk.body+"_"+lang,
|
||||
html: false
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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": "Sans",
|
||||
"FONTSETTINGS_SERIF": "Serif"
|
||||
}
|
||||
Reference in New Issue
Block a user