summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--README.md20
-rw-r--r--bin/build.js7
-rw-r--r--bin/utils.js4
-rw-r--r--lib/generate/index.js66
-rw-r--r--lib/generate/json/index.js17
-rw-r--r--lib/parse/readme.js23
-rw-r--r--package.json2
-rw-r--r--theme/templates/includes/book/summary.html6
8 files changed, 107 insertions, 38 deletions
diff --git a/README.md b/README.md
index 326aae4..a389224 100644
--- a/README.md
+++ b/README.md
@@ -3,7 +3,7 @@ GitBook
[![Build Status](https://travis-ci.org/GitbookIO/gitbook.png?branch=master)](https://travis-ci.org/GitbookIO/gitbook)
-GitBook is a command line tool (and Node.js library) for building beautiful programming books and exercises using GitHub/Git and Markdown. You can see an example: [Learn Javascript](http://gitbookio.github.io/javascript/). An [editor](https://github.com/GitbookIO/editor) is available for Windows, Mac and Linux. You can follow [@GitBookIO](https://twitter.com/GitBookIO) on Twitter.
+GitBook is a command line tool (and Node.js library) for building beautiful books and exercises using GitHub/Git and Markdown. You can see an example: [Learn Javascript](https://www.gitbook.io/book/GitBookIO/javascript). An [editor](https://github.com/GitbookIO/editor) is available for Windows, Mac and Linux. You can follow [@GitBookIO](https://twitter.com/GitBookIO) on Twitter.
![Image](https://raw.github.com/GitbookIO/gitbook/master/preview.png)
@@ -106,11 +106,11 @@ GitBook can generate your book in the following formats:
## Book Format
-A book is a GitHub repository containing at least 2 files: `README.md` and `SUMMARY.md`.
+A book is a Git repository containing at least 2 files: `README.md` and `SUMMARY.md`.
#### README.md
-As usual, it should contains an introduction for your book. It will be automatically added to the final summary.
+Typically, this should be the introduction for your book. It will be automatically added to the final summary.
#### SUMMARY.md
@@ -130,7 +130,7 @@ This is the summary of my book.
* [example 1](section2/example1.md)
```
-Files that are not included in the `SUMMARY.md` will not be processed by `gitbook`.
+Files that are not included in `SUMMARY.md` will not be processed by `gitbook`.
#### Exercises
@@ -189,8 +189,14 @@ GitBook will read the `.gitignore`, `.bookignore` and `.ignore` files to get a l
#### Cover
-A cover image can be set by creating a file: **/cover.jpg** or **cover.png**.
-The best resolution is **1600x2400**. The generation of the cover can be done automatically using the plugin [autocover](https://github.com/GitbookIO/plugin-autocover).
+A cover image can be set by creating a file: **/cover.jpg**.
+The best resolution is **1800x2360**. The generation of the cover can be done automatically using the plugin [autocover](https://github.com/GitbookIO/plugin-autocover).
+
+A small version of the cover can also be set by creating a file: **/cover_small.jpg**.
+
+#### Publish your book
+
+The platform [GitBook.io](https://www.gitbook.io/) is like an "Heroku for books", you can create a book on it (public, paid, or private) and update it using **git push**.
#### Plugins
@@ -207,7 +213,7 @@ Plugins can used to extend your book's functionality. Read [GitbookIO/plugin](ht
* [Disqus](https://github.com/GitbookIO/plugin-disqus): Disqus comments integration in your book
* [Autocover](https://github.com/GitbookIO/plugin-autocover): Generate a cover for your book
* [Transform annoted quotes to notes](https://github.com/erixtekila/gitbook-plugin-richquotes): Allow extra markdown markup to render blockquotes as nice notes
-* [Send code to console](https://github.com/erixtekila/gitbook-plugin-toconsole): Evaluate javascript blockin the browser inspector's console
+* [Send code to console](https://github.com/erixtekila/gitbook-plugin-toconsole): Evaluate javascript block in the browser inspector's console
* [Revealable sections](https://github.com/mrpotes/gitbook-plugin-reveal): Reveal sections of the page using buttons made from the first title in each section
* [Markdown within HTML](https://github.com/mrpotes/gitbook-plugin-nestedmd): Process markdown within HTML blocks - allows custom layout options for individual pages
* [Bootstrap JavaScript plugins](https://github.com/mrpotes/gitbook-plugin-bootstrapjs): Use the [Bootstrap JavaScript plugins](http://getbootstrap.com/javascript) in your online GitBook
diff --git a/bin/build.js b/bin/build.js
index 257715d..5894d00 100644
--- a/bin/build.js
+++ b/bin/build.js
@@ -33,8 +33,11 @@ var makeBuildFunc = function(converter) {
.then(function(output) {
console.log("Successfuly built !");
return output;
- }, utils.logError);
- };
+ }, utils.logError)
+ .fail(function() {
+ process.exit(-1);
+ });
+ };
};
module.exports = {
diff --git a/bin/utils.js b/bin/utils.js
index b43936f..74a09b5 100644
--- a/bin/utils.js
+++ b/bin/utils.js
@@ -30,7 +30,9 @@ function watch(dir) {
}
function logError(err) {
- console.log(err.stack || err.message || err);
+ var message = err.message || err;
+ if (process.env.DEBUG != null) message = err.stack || message;
+ console.log(message);
return Q.reject(err);
};
diff --git a/lib/generate/index.js b/lib/generate/index.js
index 6a07a21..8c6450c 100644
--- a/lib/generate/index.js
+++ b/lib/generate/index.js
@@ -67,7 +67,9 @@ var generate = function(options) {
// Links
"links": {
- "about": null
+ "about": null,
+ "issues": null,
+ "contribue": null,
}
});
@@ -82,7 +84,24 @@ var generate = function(options) {
}
// Check files to get folder type (book, multilanguage book or neither)
- return containsFiles(options.input, ['LANGS.md'])
+ return Q()
+
+ // Read readme
+ .then(function() {
+ return fs.readFile(path.join(options.input, "README.md"), "utf-8")
+ .then(function(_readme) {
+ _readme = parse.readme(_readme);
+
+ options.title = options.title || _readme.title;
+ options.description = options.description || _readme.description || defaultDescription;
+ });
+ })
+
+ // Detect multi-languages book
+ .then(function() {
+ return containsFiles(options.input, ['LANGS.md'])
+ })
+
.then(function(isMultiLang) {
// Multi language book
if(isMultiLang) {
@@ -96,24 +115,34 @@ var generate = function(options) {
var generateMultiLang = function(options) {
+ var langsSummary;
options.output = options.output || path.join(options.input, "_book");
// Multi-languages book
return fs.readFile(path.join(options.input, "LANGS.md"), "utf-8")
- // Generate sub-books
+ // Clean output folder
.then(function(_langsSummary) {
- options.langsSummary = parse.langs(_langsSummary);
+ langsSummary = _langsSummary;
+ return fs.remove(options.output);
+ })
+ .then(function() {
+ return fs.mkdirp(options.output);
+ })
+
+ // Generate sub-books
+ .then(function() {
+ options.langsSummary = parse.langs(langsSummary);
// Generated a book for each valid entry
- return Q.all(
- _.map(options.langsSummary.list, function(entry) {
+ return _.reduce(options.langsSummary.list, function(prev, entry) {
+ return prev.then(function() {
return generate(_.extend({}, options, {
input: path.join(options.input, entry.path),
output: path.join(options.output, entry.path)
}));
})
- );
+ }, Q());
})
.then(function() {
@@ -170,6 +199,16 @@ var generateBook = function(options) {
// Get repo's URL
.then(function() {
+ // Git deactivated
+ if(options.github === false) {
+ options.github = null;
+ return null;
+ } else if(options.github) {
+ // Git already specified in options
+ return options.github;
+ }
+
+ // Try auto detecting
return parse.git.url(options.input)
.then(function(_url) {
// Get ID of repo
@@ -178,7 +217,7 @@ var generateBook = function(options) {
return null;
})
.then(function(repoId) {
- options.github = options.github || repoId;
+ options.github = repoId;
});
})
@@ -203,17 +242,6 @@ var generateBook = function(options) {
// Generate the book
return Q()
- // Read readme
- .then(function() {
- return fs.readFile(path.join(options.input, "README.md"), "utf-8")
- .then(function(_readme) {
- _readme = parse.readme(_readme);
-
- options.title = options.title || _readme.title;
- options.description = options.description || _readme.description || defaultDescription;
- });
- })
-
// Get summary
.then(function() {
return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8")
diff --git a/lib/generate/json/index.js b/lib/generate/json/index.js
index f301a7e..9e61532 100644
--- a/lib/generate/json/index.js
+++ b/lib/generate/json/index.js
@@ -40,6 +40,23 @@ Generator.prototype.convertFile = function(content, input) {
});
};
+// Generate languages index
+Generator.prototype.langsIndex = function(langs) {
+ var that = this;
+
+ var json = {
+ langs: langs.list
+ };
+
+ return Q()
+ .then(function() {
+ return fs.writeFile(
+ path.join(that.options.output, "langs.json"),
+ JSON.stringify(json, null, 4)
+ );
+ });
+};
+
Generator.prototype.finish = function() {
// ignore
};
diff --git a/lib/parse/readme.js b/lib/parse/readme.js
index aab094d..85a8749 100644
--- a/lib/parse/readme.js
+++ b/lib/parse/readme.js
@@ -1,5 +1,6 @@
var _ = require('lodash');
var marked = require('marked');
+var textRenderer = require('marked-text-renderer');
function extractFirstNode(nodes, nType) {
return _.chain(nodes)
@@ -14,16 +15,28 @@ function extractFirstNode(nodes, nType) {
function parseReadme(src) {
var nodes, title, description;
+ var renderer = textRenderer();
// Parse content
nodes = marked.lexer(src);
-
- var title = extractFirstNode(nodes, "heading");
- var description = extractFirstNode(nodes, "paragraph");
+
+ title = extractFirstNode(nodes, "heading") || '';
+ description = extractFirstNode(nodes, "paragraph") || '';
+
+ var convert = _.compose(
+ function(text) {
+ return _.unescape(text.replace(/(\r\n|\n|\r)/gm, ""));
+ },
+ function(text) {
+ return marked.parse(text, _.extend({}, marked.defaults, {
+ renderer: renderer
+ }));
+ }
+ );
return {
- title: title,
- description: description
+ title: convert(title),
+ description: convert(description)
};
}
diff --git a/package.json b/package.json
index d8474d8..0e3c7f5 100644
--- a/package.json
+++ b/package.json
@@ -1,6 +1,6 @@
{
"name": "gitbook",
- "version": "0.4.2",
+ "version": "0.4.5",
"homepage": "http://www.gitbook.io/",
"description": "Library and cmd utility to generate GitBooks",
"main": "lib/index.js",
diff --git a/theme/templates/includes/book/summary.html b/theme/templates/includes/book/summary.html
index 29fbd8c..02fe2a7 100644
--- a/theme/templates/includes/book/summary.html
+++ b/theme/templates/includes/book/summary.html
@@ -3,19 +3,19 @@
<input type="text" placeholder="Search" class="form-control" />
</div>
<ul class="summary">
- {% if options.links.about !== false && (options.links.about != null || githubId) %}
+ {% if options.links.about !== false && (options.links.about || githubId) %}
<li>
<a href="{{ options.links.about|default(githubHost+githubAuthor) }}" target="blank" class="author-link">About the author</a>
</li>
{% endif %}
- {% if options.links.issues !== false && (options.links.issues != null || githubId) %}
+ {% if options.links.issues !== false && (options.links.issues || githubId) %}
<li>
<a href="{{ options.links.issues|default(githubHost+githubId+"/issues") }}" target="blank"class="issues-link">Questions and Issues</a>
</li>
{% endif %}
- {% if options.links.contribute !== false && (options.links.contribute != null || githubId) %}
+ {% if options.links.contribute !== false && (options.links.contribute || githubId) %}
<li>
<a href="{{ options.links.contribute|default(githubHost+githubId+"/edit/master/"+_input) }}" target="blank" class="contribute-link">Edit and Contribute</a>
</li>