mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-21 01:53:26 +00:00
Always generate README.json with langs index
remove method langsIndex form generators (moved to finish)
This commit is contained in:
+5
-3
@@ -261,9 +261,6 @@ Book.prototype.generateMultiLingual = function(generator) {
|
||||
return book.generate(that.options.generator);
|
||||
});
|
||||
}, Q());
|
||||
})
|
||||
.then(function() {
|
||||
return generator.langsIndex(that.langs);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -651,6 +648,11 @@ Book.prototype.isSubBook = function() {
|
||||
return !!this.parent;
|
||||
};
|
||||
|
||||
// Test if the file is the entry point
|
||||
Book.prototype.isEntryPoint = function(fp) {
|
||||
return fp == this.readmeFile;
|
||||
};
|
||||
|
||||
// Resolve a path in book
|
||||
Book.prototype.resolve = function(p) {
|
||||
return path.resolve(this.root, p);
|
||||
|
||||
@@ -70,11 +70,6 @@ BaseGenerator.prototype.copyCover = function() {
|
||||
});
|
||||
};
|
||||
|
||||
// Generate the langs index
|
||||
BaseGenerator.prototype.langsIndex = function(langs) {
|
||||
return Q.reject(new Error("Langs index is not supported in this generator"));
|
||||
};
|
||||
|
||||
// At teh end of the generation
|
||||
BaseGenerator.prototype.finish = function() {
|
||||
return Q.reject(new Error("Could not finish generation"));
|
||||
|
||||
@@ -41,11 +41,6 @@ Generator.prototype.writeSummary = function() {
|
||||
return this._writeTemplate(this.templates["summary"], {}, path.join(this.options.output, "SUMMARY.html"));
|
||||
};
|
||||
|
||||
|
||||
Generator.prototype.langsIndex = function(langs) {
|
||||
return Q();
|
||||
};
|
||||
|
||||
Generator.prototype.finish = function() {
|
||||
var that = this;
|
||||
|
||||
|
||||
+14
-10
@@ -14,7 +14,6 @@ util.inherits(Generator, BaseGenerator);
|
||||
|
||||
// Ignore some methods
|
||||
Generator.prototype.transferFile = function(input) { };
|
||||
Generator.prototype.finish = function() { };
|
||||
|
||||
// Convert an input file
|
||||
Generator.prototype.convertFile = function(input) {
|
||||
@@ -37,21 +36,26 @@ Generator.prototype.convertFile = function(input) {
|
||||
});
|
||||
};
|
||||
|
||||
// Generate languages index
|
||||
// Contains the first languages readme and langs infos
|
||||
Generator.prototype.langsIndex = function(langs) {
|
||||
// Finish generation
|
||||
Generator.prototype.finish = function() {
|
||||
return this.writeReadme();
|
||||
};
|
||||
|
||||
// Write README.json
|
||||
Generator.prototype.writeReadme = function() {
|
||||
var that = this;
|
||||
|
||||
if (langs.length == 0) return Q.reject("Need at least one language");
|
||||
|
||||
var mainLang = _.first(langs).lang;
|
||||
var readme = links.changeExtension(that.book.readmeFile, ".json");
|
||||
var mainlang, langs;
|
||||
|
||||
return Q()
|
||||
.then(function() {
|
||||
langs = that.book.langs;
|
||||
mainLang = langs.length > 0? _.first(langs).lang : null;
|
||||
|
||||
readme = links.changeExtension(that.book.readmeFile, ".json");
|
||||
|
||||
// Read readme from main language
|
||||
return fs.readFile(
|
||||
path.join(that.options.output, mainLang, readme)
|
||||
mainLang? path.join(that.options.output, mainLang, readme) : path.join(that.options.output, readme)
|
||||
);
|
||||
})
|
||||
.then(function(content) {
|
||||
|
||||
@@ -118,7 +118,8 @@ Generator.prototype.finish = function() {
|
||||
return this.copyAssets()
|
||||
.then(this.copyCover)
|
||||
.then(this.writeGlossary)
|
||||
.then(this.writeSearchIndex);
|
||||
.then(this.writeSearchIndex)
|
||||
.then(this.writeLangsIndex)
|
||||
};
|
||||
|
||||
// Convert an input file
|
||||
@@ -156,11 +157,11 @@ Generator.prototype.convertFile = function(input) {
|
||||
};
|
||||
|
||||
// Write the index for langs
|
||||
Generator.prototype.langsIndex = function(langs) {
|
||||
Generator.prototype.writeLangsIndex = function() {
|
||||
var that = this;
|
||||
|
||||
if (!this.book.langs.length) return Q();
|
||||
return this._writeTemplate(this.templates["langs"], {
|
||||
langs: langs
|
||||
langs: this.book.langs
|
||||
}, path.join(this.options.output, "index.html"));
|
||||
};
|
||||
|
||||
|
||||
+1
-1
@@ -16,7 +16,7 @@ describe('JSON generator', function () {
|
||||
|
||||
it('should correctly generate a book to json with sub folders', function(done) {
|
||||
testGeneration(books[1], "json", function(output) {
|
||||
assert(!fs.existsSync(path.join(output, "README.json")));
|
||||
assert(fs.existsSync(path.join(output, "README.json")));
|
||||
assert(fs.existsSync(path.join(output, "intro.json")));
|
||||
assert(fs.existsSync(path.join(output, "sub/test1.json")));
|
||||
|
||||
|
||||
Reference in New Issue
Block a user