mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-29 21:49:26 +00:00
Compare commits
22 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f998e2dec9 | |||
| 2c0bd53a91 | |||
| 6dd7f6162f | |||
| 475b0bb2b3 | |||
| e6343935e3 | |||
| 946883fd4c | |||
| b1b7e3148b | |||
| 32203f6438 | |||
| f2d3c5d2ed | |||
| 7e2f0ed4bc | |||
| a877acf905 | |||
| ac756ddf7e | |||
| 36e2236e6b | |||
| 72df665520 | |||
| 07785528a5 | |||
| bb579dd581 | |||
| a7d3064340 | |||
| 1a60778248 | |||
| cda4bb5bda | |||
| 7543781046 | |||
| 82f3ffad06 | |||
| dc4d2a1731 |
+10
@@ -2,6 +2,16 @@
|
|||||||
All notable changes to this project will be documented in this file.
|
All notable changes to this project will be documented in this file.
|
||||||
This project adheres to [Semantic Versioning](http://semver.org/).
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
||||||
|
|
||||||
|
## 2.0.4
|
||||||
|
- Fix `{% raw %}`, got confused with "fake" variable declarations
|
||||||
|
- Fix title of language chooser
|
||||||
|
- Fix the X-UA-Compatible meta tag
|
||||||
|
- Move style sheets to the <head> section
|
||||||
|
|
||||||
|
## 2.0.3
|
||||||
|
- Fix `gitbook init` for SUMMARY with empty entries
|
||||||
|
- Fix escaping of code blocks in markdown
|
||||||
|
|
||||||
## 2.0.2
|
## 2.0.2
|
||||||
- Fix relative links in windows
|
- Fix relative links in windows
|
||||||
- Improve watcher in serve command (switch to chokidar)
|
- Improve watcher in serve command (switch to chokidar)
|
||||||
|
|||||||
+15
-11
@@ -789,20 +789,19 @@ Book.prototype.normError = function(err, opts, defs) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
// Init and return a book
|
// Init and return a book
|
||||||
Book.init = function(root) {
|
Book.init = function(root, opts) {
|
||||||
var book = new Book(root);
|
var book = new Book(root, opts);
|
||||||
var extensionToUse = ".md";
|
var extensionToUse = ".md";
|
||||||
|
|
||||||
var chaptersPaths = function(chapters) {
|
var chaptersPaths = function(chapters) {
|
||||||
return _.reduce(chapters || [], function(accu, chapter) {
|
return _.reduce(chapters || [], function(accu, chapter) {
|
||||||
if (!chapter.path) return accu;
|
var o = {
|
||||||
|
title: chapter.title
|
||||||
|
};
|
||||||
|
if (chapter.path) o.path = chapter.path;
|
||||||
|
|
||||||
return accu.concat(
|
return accu.concat(
|
||||||
_.filter([
|
[o].concat(chaptersPaths(chapter.articles))
|
||||||
{
|
|
||||||
title: chapter.title,
|
|
||||||
path: chapter.path
|
|
||||||
}
|
|
||||||
].concat(chaptersPaths(chapter.articles)))
|
|
||||||
);
|
);
|
||||||
}, []);
|
}, []);
|
||||||
};
|
};
|
||||||
@@ -839,12 +838,17 @@ Book.init = function(root) {
|
|||||||
.then(function(chapters) {
|
.then(function(chapters) {
|
||||||
// Create files that don't exist
|
// Create files that don't exist
|
||||||
return Q.all(_.map(chapters, function(chapter) {
|
return Q.all(_.map(chapters, function(chapter) {
|
||||||
|
if (!chapter.path) return Q();
|
||||||
var absolutePath = path.resolve(book.root, chapter.path);
|
var absolutePath = path.resolve(book.root, chapter.path);
|
||||||
|
|
||||||
return fs.exists(absolutePath)
|
return fs.exists(absolutePath)
|
||||||
.then(function(exists) {
|
.then(function(exists) {
|
||||||
book.log.info.ln("create", chapter.path);
|
if(exists) {
|
||||||
if(exists) return;
|
book.log.info.ln("found", chapter.path);
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
book.log.info.ln("create", chapter.path);
|
||||||
|
}
|
||||||
|
|
||||||
return fs.mkdirp(path.dirname(absolutePath))
|
return fs.mkdirp(path.dirname(absolutePath))
|
||||||
.then(function() {
|
.then(function() {
|
||||||
|
|||||||
@@ -4,8 +4,8 @@ var Q = require("q");
|
|||||||
var _ = require("lodash");
|
var _ = require("lodash");
|
||||||
|
|
||||||
var nunjucks = require("nunjucks");
|
var nunjucks = require("nunjucks");
|
||||||
var AutoEscapeExtension = require("nunjucks-autoescape");
|
var AutoEscapeExtension = require("nunjucks-autoescape")(nunjucks);
|
||||||
var FilterExtension = require("nunjucks-filter");
|
var FilterExtension = require("nunjucks-filter")(nunjucks);
|
||||||
|
|
||||||
var fs = require("../utils/fs");
|
var fs = require("../utils/fs");
|
||||||
var BaseGenerator = require("../generator");
|
var BaseGenerator = require("../generator");
|
||||||
@@ -100,7 +100,6 @@ Generator.prototype.prepareTemplateEngine = function() {
|
|||||||
that.env.addFilter('lvl', function(lvl) {
|
that.env.addFilter('lvl', function(lvl) {
|
||||||
return lvl.split(".").length;
|
return lvl.split(".").length;
|
||||||
});
|
});
|
||||||
that.env.addGlobal('__', that.book.i18n.bind(that.book));
|
|
||||||
|
|
||||||
// Add extension
|
// Add extension
|
||||||
that.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(that.env));
|
that.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(that.env));
|
||||||
@@ -238,6 +237,8 @@ Generator.prototype._writeTemplate = function(tpl, options, output, interpolate)
|
|||||||
|
|
||||||
basePath: ".",
|
basePath: ".",
|
||||||
staticBase: path.join(".", "gitbook"),
|
staticBase: path.join(".", "gitbook"),
|
||||||
|
|
||||||
|
'__': that.book.i18n.bind(that.book)
|
||||||
}, options)
|
}, options)
|
||||||
);
|
);
|
||||||
})
|
})
|
||||||
|
|||||||
+1
-1
@@ -155,7 +155,7 @@ Plugin.prototype.callHook = function(name, data) {
|
|||||||
if (!hookFunc) return Q(data);
|
if (!hookFunc) return Q(data);
|
||||||
|
|
||||||
this.book.log.debug.ln("call hook", name);
|
this.book.log.debug.ln("call hook", name);
|
||||||
if (!_.contains(Plugin.HOOKS, name)) this.book.log.warn.ln("hook '"+name+"' used by plugin '"+this.name+"' is deprecated, and will be remove in the coming versions");
|
if (!_.contains(Plugin.HOOKS, name)) this.book.log.warn.ln("hook '"+name+"' used by plugin '"+this.name+"' is deprecated, and will be removed in the coming versions");
|
||||||
|
|
||||||
return Q()
|
return Q()
|
||||||
.then(function() {
|
.then(function() {
|
||||||
|
|||||||
+5
-2
@@ -237,13 +237,16 @@ function normalizeHtml(src, options) {
|
|||||||
});
|
});
|
||||||
|
|
||||||
// Replace glossary terms
|
// Replace glossary terms
|
||||||
_.each(options.glossary, function(term) {
|
var glossary = _.sortBy(options.glossary, function(term) {
|
||||||
|
return -term.name.length;
|
||||||
|
});
|
||||||
|
_.each(glossary, function(term) {
|
||||||
var r = new RegExp( "\\b(" + pregQuote(term.name.toLowerCase()) + ")\\b" , 'gi' );
|
var r = new RegExp( "\\b(" + pregQuote(term.name.toLowerCase()) + ")\\b" , 'gi' );
|
||||||
var includedInFiles = false;
|
var includedInFiles = false;
|
||||||
|
|
||||||
$("*").each(function() {
|
$("*").each(function() {
|
||||||
// Ignore codeblocks
|
// Ignore codeblocks
|
||||||
if (_.contains(["code", "pre"], this.name.toLowerCase())) return;
|
if (_.contains(["code", "pre", "a"], this.name.toLowerCase())) return;
|
||||||
|
|
||||||
replaceText($, this, r, function(match) {
|
replaceText($, this, r, function(match) {
|
||||||
// Add to files index in glossary
|
// Add to files index in glossary
|
||||||
|
|||||||
+6
-6
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gitbook",
|
"name": "gitbook",
|
||||||
"version": "2.0.2",
|
"version": "2.0.4",
|
||||||
"homepage": "https://www.gitbook.com",
|
"homepage": "https://www.gitbook.com",
|
||||||
"description": "Library and cmd utility to generate GitBooks",
|
"description": "Library and cmd utility to generate GitBooks",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
@@ -12,10 +12,10 @@
|
|||||||
"resolve": "0.6.3",
|
"resolve": "0.6.3",
|
||||||
"fs-extra": "0.16.5",
|
"fs-extra": "0.16.5",
|
||||||
"fstream-ignore": "1.0.2",
|
"fstream-ignore": "1.0.2",
|
||||||
"gitbook-parsers": "0.7.4",
|
"gitbook-parsers": "0.7.5",
|
||||||
"nunjucks": "1.3.0",
|
"nunjucks": "mozilla/nunjucks#103513c294835bcbe64222de6db494e2555e294e",
|
||||||
"nunjucks-autoescape": "0.1.1",
|
"nunjucks-autoescape": "1.0.0",
|
||||||
"nunjucks-filter": "0.1.0",
|
"nunjucks-filter": "1.0.0",
|
||||||
"i18n": "0.5.0",
|
"i18n": "0.5.0",
|
||||||
"semver": "2.2.1",
|
"semver": "2.2.1",
|
||||||
"npmi": "0.1.1",
|
"npmi": "0.1.1",
|
||||||
@@ -61,7 +61,7 @@
|
|||||||
"gitbook"
|
"gitbook"
|
||||||
],
|
],
|
||||||
"author": "FriendCode Inc. <contact@gitbook.com>",
|
"author": "FriendCode Inc. <contact@gitbook.com>",
|
||||||
"license": "Apache 2",
|
"license": "Apache-2.0",
|
||||||
"bugs": {
|
"bugs": {
|
||||||
"url": "https://github.com/GitbookIO/gitbook/issues"
|
"url": "https://github.com/GitbookIO/gitbook/issues"
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -7,3 +7,7 @@ Just a simple and easy to understand test.
|
|||||||
## hakunamatata
|
## hakunamatata
|
||||||
|
|
||||||
This word is not present in the content.
|
This word is not present in the content.
|
||||||
|
|
||||||
|
## test long
|
||||||
|
|
||||||
|
This is a test with a longer text that the first entry to test order.
|
||||||
|
|||||||
@@ -6,3 +6,5 @@ The word test should be replaced by a glossary link.
|
|||||||
But the word test should not be replaced in code blocks
|
But the word test should not be replaced in code blocks
|
||||||
```
|
```
|
||||||
|
|
||||||
|
The two words test long should be replaced by the correct glossary links.
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
*
|
||||||
|
!SUMMARY.md
|
||||||
|
!.gitignore
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
# Summary
|
||||||
|
|
||||||
|
* [Hello](hello.md)
|
||||||
|
* [Hello 2](hello2.md)
|
||||||
|
* Hello 3
|
||||||
|
* [Hello 4](hello3/hello4.md)
|
||||||
+10
-1
@@ -14,7 +14,7 @@ describe('Glossary', function () {
|
|||||||
|
|
||||||
it('should correctly list items', function() {
|
it('should correctly list items', function() {
|
||||||
book.should.have.property("glossary");
|
book.should.have.property("glossary");
|
||||||
book.glossary.should.have.lengthOf(2);
|
book.glossary.should.have.lengthOf(3);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -73,6 +73,15 @@ describe('Glossary', function () {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should correctly select the longest term', function() {
|
||||||
|
readme.should.be.html({
|
||||||
|
".page-inner a[href='GLOSSARY.html#test_long']": {
|
||||||
|
count: 1,
|
||||||
|
text: "test long"
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,23 @@
|
|||||||
|
var fs = require('fs');
|
||||||
|
var path = require('path');
|
||||||
|
var should = require('should');
|
||||||
|
|
||||||
|
var Book = require('../').Book;
|
||||||
|
var LOG_LEVELS = require('../').LOG_LEVELS;
|
||||||
|
|
||||||
|
describe('Init Books', function () {
|
||||||
|
var initRoot;
|
||||||
|
|
||||||
|
before(function() {
|
||||||
|
initRoot = path.resolve(__dirname, "books/init");
|
||||||
|
return Book.init(initRoot, {
|
||||||
|
logLevel: LOG_LEVELS.DISABLED,
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should create all chapters', function() {
|
||||||
|
should(fs.existsSync(path.resolve(initRoot, "hello.md"))).be.ok;
|
||||||
|
should(fs.existsSync(path.resolve(initRoot, "hello2.md"))).be.ok;
|
||||||
|
should(fs.existsSync(path.resolve(initRoot, "hello3/hello4.md"))).be.ok;
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -16,6 +16,9 @@ define([
|
|||||||
},
|
},
|
||||||
"instapaper": function($el) {
|
"instapaper": function($el) {
|
||||||
window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href));
|
window.open("http://www.instapaper.com/text?u="+encodeURIComponent(location.href));
|
||||||
|
},
|
||||||
|
"vk": function($el) {
|
||||||
|
window.open("http://vkontakte.ru/share.php?url="+encodeURIComponent(location.href));
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,8 @@
|
|||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html lang="{{ language }}" {% block htmlTag %}{% endblock %} {% if options.direction == "rtl" %}dir="rtl"{% endif %}>
|
<html lang="{{ language }}" {% block htmlTag %}{% endblock %} {% if options.direction == "rtl" %}dir="rtl"{% endif %}>
|
||||||
{{ htmlSnippet("html:start")|default("")|safe }}
|
{{ htmlSnippet("html:start")|default("", true)|safe }}
|
||||||
<head>
|
<head>
|
||||||
{{ htmlSnippet("head:start")|default("")|safe }}
|
{{ htmlSnippet("head:start")|default("", true)|safe }}
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>{% block title %}{% endblock %}</title>
|
<title>{% block title %}{% endblock %}</title>
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||||
@@ -11,14 +11,14 @@
|
|||||||
{% if options.author %}<meta name="author" content="{{ options.author }}">{% endif %}
|
{% if options.author %}<meta name="author" content="{{ options.author }}">{% endif %}
|
||||||
{% if options.isbn %}<meta name="identifier" content="{{ options.isbn }}" scheme="ISBN">{% endif %}
|
{% if options.isbn %}<meta name="identifier" content="{{ options.isbn }}" scheme="ISBN">{% endif %}
|
||||||
{% block head %}{% endblock %}
|
{% block head %}{% endblock %}
|
||||||
{{ htmlSnippet("head:end")|default("")|safe }}
|
{{ htmlSnippet("head:end")|default("", true)|safe }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{{ htmlSnippet("body:start")|default("")|safe }}
|
{{ htmlSnippet("body:start")|default("", true)|safe }}
|
||||||
{% block style %}{% endblock %}
|
{% block style %}{% endblock %}
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
{% block javascript %}{% endblock %}
|
{% block javascript %}{% endblock %}
|
||||||
{{ htmlSnippet("body:end")|default("")|safe }}
|
{{ htmlSnippet("body:end")|default("", true)|safe }}
|
||||||
</body>
|
</body>
|
||||||
{{ htmlSnippet("html:end")|default("")|safe }}
|
{{ htmlSnippet("html:end")|default("", true)|safe }}
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
@@ -54,6 +54,10 @@
|
|||||||
{% if options.links.sharing.weibo == true %}
|
{% if options.links.sharing.weibo == true %}
|
||||||
<a href="#" target="_blank" class="btn pull-right weibo-sharing-link sharing-link" data-sharing="weibo" aria-label="Weibo"><i class="fa fa-weibo"></i></a>
|
<a href="#" target="_blank" class="btn pull-right weibo-sharing-link sharing-link" data-sharing="weibo" aria-label="Weibo"><i class="fa fa-weibo"></i></a>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
{% if options.links.sharing.vk == true %}
|
||||||
|
<a href="#" target="_blank" class="btn pull-right vk-sharing-link sharing-link" data-sharing="vk" aria-label="VK"><i class="fa fa-vk"></i></a>
|
||||||
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
<!-- Title -->
|
<!-- Title -->
|
||||||
<h1>
|
<h1>
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
{% extends "./layout.html" %}
|
{% extends "./layout.html" %}
|
||||||
|
|
||||||
{% block title %}{{ title }}{% endblock %}
|
{% block title %}{{ __("LANGS_CHOOSE") }} | {{ title }}{% endblock %}
|
||||||
|
|
||||||
{% block style %}
|
{% block style %}
|
||||||
<link rel="stylesheet" href="{{ staticBase }}/style.css">
|
<link rel="stylesheet" href="{{ staticBase }}/style.css">
|
||||||
|
|||||||
@@ -1,10 +1,10 @@
|
|||||||
<!DOCTYPE HTML>
|
<!DOCTYPE HTML>
|
||||||
<html lang="{{ language }}" {% if options.direction == "rtl" %}dir="rtl"{% endif %}>
|
<html lang="{{ language }}" {% if options.direction == "rtl" %}dir="rtl"{% endif %}>
|
||||||
{{ htmlSnippet("html:start")|default("")|safe }}
|
{{ htmlSnippet("html:start")|default("", true)|safe }}
|
||||||
<head>
|
<head>
|
||||||
{{ htmlSnippet("head:start")|default("")|safe }}
|
{{ htmlSnippet("head:start")|default("", true)|safe }}
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<meta http-equiv="X-UA-Compatible" content="IE=11; IE=10; IE=9; IE=8; IE=7; IE=EDGE" />
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
||||||
<title>{% block title %}{% endblock %}</title>
|
<title>{% block title %}{% endblock %}</title>
|
||||||
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
||||||
<meta name="description" content="{% block description %}{% endblock %}">
|
<meta name="description" content="{% block description %}{% endblock %}">
|
||||||
@@ -17,15 +17,15 @@
|
|||||||
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
||||||
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="{{ staticBase }}/images/apple-touch-icon-precomposed-152.png">
|
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="{{ staticBase }}/images/apple-touch-icon-precomposed-152.png">
|
||||||
<link rel="shortcut icon" href="{{ staticBase }}/images/favicon.ico" type="image/x-icon">
|
<link rel="shortcut icon" href="{{ staticBase }}/images/favicon.ico" type="image/x-icon">
|
||||||
|
{% block style %}{% endblock %}
|
||||||
{% block head %}{% endblock %}
|
{% block head %}{% endblock %}
|
||||||
{{ htmlSnippet("head:end")|default("")|safe }}
|
{{ htmlSnippet("head:end")|default("", true)|safe }}
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<body>
|
||||||
{{ htmlSnippet("body:start")|default("")|safe }}
|
{{ htmlSnippet("body:start")|default("", true)|safe }}
|
||||||
{% block style %}{% endblock %}
|
|
||||||
{% block content %}{% endblock %}
|
{% block content %}{% endblock %}
|
||||||
{% block javascript %}{% endblock %}
|
{% block javascript %}{% endblock %}
|
||||||
{{ htmlSnippet("body:end")|default("")|safe }}
|
{{ htmlSnippet("body:end")|default("", true)|safe }}
|
||||||
</body>
|
</body>
|
||||||
{{ htmlSnippet("html:end")|default("")|safe }}
|
{{ htmlSnippet("html:end")|default("", true)|safe }}
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user