mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Fix parsing of langs
Add command to build
This commit is contained in:
+15
-5
@@ -22,10 +22,10 @@ var Book = function(root, options) {
|
||||
this.summary = {};
|
||||
|
||||
// Glossary
|
||||
this.glossary = {};
|
||||
this.glossary = [];
|
||||
|
||||
// Langs
|
||||
this.langs = {};
|
||||
this.langs = [];
|
||||
};
|
||||
|
||||
// Initialize and parse the book: config, summary, glossary
|
||||
@@ -38,10 +38,10 @@ Book.prototype.init = function() {
|
||||
.then(function() {
|
||||
return that.parseLangs()
|
||||
.then(function() {
|
||||
multilingal = that.langs.list.length > 0;
|
||||
multilingal = that.langs.length > 0;
|
||||
|
||||
// Sub-books that inherit from the current book configuration
|
||||
that.books = _.map(that.langs.list, function(lang) {
|
||||
that.books = _.map(that.langs, function(lang) {
|
||||
return new Book(
|
||||
path.join(that.root, lang.path),
|
||||
_.extend({}, that.options, {
|
||||
@@ -63,13 +63,23 @@ Book.prototype.init = function() {
|
||||
.thenResolve(this);
|
||||
};
|
||||
|
||||
// Generate the output
|
||||
Book.prototype.generate = function() {
|
||||
var that = this;
|
||||
|
||||
return this.init()
|
||||
.then(function() {
|
||||
|
||||
});
|
||||
};
|
||||
|
||||
// Parse langs
|
||||
Book.prototype.parseLangs = function() {
|
||||
var that = this;
|
||||
|
||||
return that.findFile("LANGS")
|
||||
.then(function(langs) {
|
||||
if (!langs) return {};
|
||||
if (!langs) return [];
|
||||
|
||||
return that.readFile(langs.path)
|
||||
.then(function(content) {
|
||||
|
||||
@@ -16,10 +16,10 @@ Configuration.prototype.load = function() {
|
||||
return Q()
|
||||
.then(function() {
|
||||
try {
|
||||
var _config = require(path.resolve(that.book.root, that.options.));
|
||||
var _config = require(path.resolve(that.book.root, that.options.configFile));
|
||||
that.options = _.merge(
|
||||
that.options,
|
||||
_.omit(_config, 'input', 'configFile', 'defaultsPlugins', 'generator')
|
||||
_.omit(_config, 'configFile', 'defaultsPlugins', 'generator', 'extension')
|
||||
);
|
||||
}
|
||||
catch(err) {
|
||||
|
||||
+22
-1
@@ -1,5 +1,26 @@
|
||||
var Q = require("q");
|
||||
var _ = require("lodash");
|
||||
var path = require("path");
|
||||
|
||||
var Book = require("./book");
|
||||
|
||||
module.exports = {
|
||||
Book: require("./book")
|
||||
Book: Book,
|
||||
|
||||
commands: [
|
||||
{
|
||||
name: "build",
|
||||
description: "Build a book",
|
||||
exec: function(args, kwargs) {
|
||||
var input = args[0] || process.cwd();
|
||||
var output = args[1] || path.join(input, "_book");
|
||||
|
||||
var book = new Book(input, _.extend({}, {
|
||||
'output': output
|
||||
}));
|
||||
|
||||
return book.generate();
|
||||
}
|
||||
}
|
||||
]
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user