Compare commits

...

9 Commits

Author SHA1 Message Date
Aaron O'Mullan 443def6cfd Bump version to 0.4.4 2014-05-20 22:59:26 -07:00
Samy Pessé 75464574d7 For multi-langs, run build one by one 2014-05-21 00:09:40 +02:00
Samy Pessé 86f05c68c5 Improve parsing of readme (extraction of title and description as plain text and not markdown) 2014-05-20 23:45:35 +02:00
Samy Pessé 8dd407eaa8 Fix merge of output for multi-languages books 2014-05-20 23:31:22 +02:00
Samy Pessé ea7ad10e8a Add support for multi-languages books in JSON format 2014-05-20 23:21:12 +02:00
Samy Pessé 62ec695dc8 Extract title and description from readme before switching to multi-languages handling 2014-05-20 23:07:41 +02:00
Samy Pessé ca37ac73a9 Add more infos about gitbook.io 2014-05-20 14:40:22 +02:00
Samy Pessé 96edd50c8f Add norm for small cover 2014-05-20 01:23:49 +02:00
Samy Pessé 3993c1e35a Change advised ratio for cover 2014-05-19 21:47:41 +02:00
5 changed files with 75 additions and 25 deletions
+10 -4
View File
@@ -3,7 +3,7 @@ GitBook
[![Build Status](https://travis-ci.org/GitbookIO/gitbook.png?branch=master)](https://travis-ci.org/GitbookIO/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) ![Image](https://raw.github.com/GitbookIO/gitbook/master/preview.png)
@@ -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
View File
@@ -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")
+17
View File
@@ -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
View File
@@ -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
View File
@@ -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",