mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-10-01 14:38:39 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 443def6cfd | |||
| 75464574d7 | |||
| 86f05c68c5 | |||
| 8dd407eaa8 | |||
| ea7ad10e8a | |||
| 62ec695dc8 | |||
| ca37ac73a9 | |||
| 96edd50c8f | |||
| 3993c1e35a |
@@ -3,7 +3,7 @@ GitBook
|
|||||||
|
|
||||||
[](https://travis-ci.org/GitbookIO/gitbook)
|
[](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.
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ GitBook can generate your book in the following formats:
|
|||||||
|
|
||||||
## Book Format
|
## 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
|
#### README.md
|
||||||
|
|
||||||
@@ -189,8 +189,14 @@ GitBook will read the `.gitignore`, `.bookignore` and `.ignore` files to get a l
|
|||||||
|
|
||||||
#### Cover
|
#### Cover
|
||||||
|
|
||||||
A cover image can be set by creating a file: **/cover.jpg** or **cover.png**.
|
A cover image can be set by creating a file: **/cover.jpg**.
|
||||||
The best resolution is **1600x2400**. The generation of the cover can be done automatically using the plugin [autocover](https://github.com/GitbookIO/plugin-autocover).
|
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
|
#### Plugins
|
||||||
|
|
||||||
|
|||||||
+33
-17
@@ -84,7 +84,24 @@ var generate = function(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Check files to get folder type (book, multilanguage book or neither)
|
// 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) {
|
.then(function(isMultiLang) {
|
||||||
// Multi language book
|
// Multi language book
|
||||||
if(isMultiLang) {
|
if(isMultiLang) {
|
||||||
@@ -98,24 +115,34 @@ var generate = function(options) {
|
|||||||
|
|
||||||
|
|
||||||
var generateMultiLang = function(options) {
|
var generateMultiLang = function(options) {
|
||||||
|
var langsSummary;
|
||||||
options.output = options.output || path.join(options.input, "_book");
|
options.output = options.output || path.join(options.input, "_book");
|
||||||
|
|
||||||
// Multi-languages book
|
// Multi-languages book
|
||||||
return fs.readFile(path.join(options.input, "LANGS.md"), "utf-8")
|
return fs.readFile(path.join(options.input, "LANGS.md"), "utf-8")
|
||||||
|
|
||||||
// Generate sub-books
|
// Clean output folder
|
||||||
.then(function(_langsSummary) {
|
.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
|
// Generated a book for each valid entry
|
||||||
return Q.all(
|
return _.reduce(options.langsSummary.list, function(prev, entry) {
|
||||||
_.map(options.langsSummary.list, function(entry) {
|
return prev.then(function() {
|
||||||
return generate(_.extend({}, options, {
|
return generate(_.extend({}, options, {
|
||||||
input: path.join(options.input, entry.path),
|
input: path.join(options.input, entry.path),
|
||||||
output: path.join(options.output, entry.path)
|
output: path.join(options.output, entry.path)
|
||||||
}));
|
}));
|
||||||
})
|
})
|
||||||
);
|
}, Q());
|
||||||
})
|
})
|
||||||
|
|
||||||
.then(function() {
|
.then(function() {
|
||||||
@@ -215,17 +242,6 @@ var generateBook = function(options) {
|
|||||||
// Generate the book
|
// Generate the book
|
||||||
return Q()
|
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
|
// Get summary
|
||||||
.then(function() {
|
.then(function() {
|
||||||
return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8")
|
return fs.readFile(path.join(options.input, "SUMMARY.md"), "utf-8")
|
||||||
|
|||||||
@@ -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() {
|
Generator.prototype.finish = function() {
|
||||||
// ignore
|
// ignore
|
||||||
};
|
};
|
||||||
|
|||||||
+14
-3
@@ -1,5 +1,6 @@
|
|||||||
var _ = require('lodash');
|
var _ = require('lodash');
|
||||||
var marked = require('marked');
|
var marked = require('marked');
|
||||||
|
var textRenderer = require('marked-text-renderer');
|
||||||
|
|
||||||
function extractFirstNode(nodes, nType) {
|
function extractFirstNode(nodes, nType) {
|
||||||
return _.chain(nodes)
|
return _.chain(nodes)
|
||||||
@@ -14,16 +15,26 @@ function extractFirstNode(nodes, nType) {
|
|||||||
|
|
||||||
function parseReadme(src) {
|
function parseReadme(src) {
|
||||||
var nodes, title, description;
|
var nodes, title, description;
|
||||||
|
var renderer = textRenderer();
|
||||||
|
|
||||||
// Parse content
|
// Parse content
|
||||||
nodes = marked.lexer(src);
|
nodes = marked.lexer(src);
|
||||||
|
|
||||||
var title = extractFirstNode(nodes, "heading");
|
var title = extractFirstNode(nodes, "heading");
|
||||||
var description = extractFirstNode(nodes, "paragraph");
|
var description = extractFirstNode(nodes, "paragraph");
|
||||||
|
|
||||||
|
var convert = _.compose(
|
||||||
|
function(text) {
|
||||||
|
return _.unescape(text.replace(/(\r\n|\n|\r)/gm, ""));
|
||||||
|
},
|
||||||
|
_.partialRight(marked, _.extend({}, marked.defaults, {
|
||||||
|
renderer: renderer
|
||||||
|
}))
|
||||||
|
);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
title: title,
|
title: convert(title),
|
||||||
description: description
|
description: convert(description)
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
{
|
{
|
||||||
"name": "gitbook",
|
"name": "gitbook",
|
||||||
"version": "0.4.3",
|
"version": "0.4.4",
|
||||||
"homepage": "http://www.gitbook.io/",
|
"homepage": "http://www.gitbook.io/",
|
||||||
"description": "Library and cmd utility to generate GitBooks",
|
"description": "Library and cmd utility to generate GitBooks",
|
||||||
"main": "lib/index.js",
|
"main": "lib/index.js",
|
||||||
|
|||||||
Reference in New Issue
Block a user