mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-16 15:45:13 +00:00
Index page of summary when parsing
This commit is contained in:
@@ -5,7 +5,7 @@ A page represent a parsable file in the book (Markdown, Asciidoc, etc)
|
||||
*/
|
||||
|
||||
function Page(book, filename) {
|
||||
if (!(this instanceof Page)) return new Page();
|
||||
if (!(this instanceof Page)) return new Page(book, filename);
|
||||
|
||||
this.book = book;
|
||||
this.filename = filename;
|
||||
@@ -20,5 +20,10 @@ Page.prototype.withExtension = function(ext) {
|
||||
);
|
||||
};
|
||||
|
||||
// Read the page as a string
|
||||
Page.prototype.read = function() {
|
||||
return this.book.readFile(this.filename);
|
||||
};
|
||||
|
||||
|
||||
module.exports = Page;
|
||||
|
||||
@@ -39,6 +39,11 @@ TOCArticle.prototype.walk = function(iter) {
|
||||
});
|
||||
};
|
||||
|
||||
// Return true if is pointing to a file
|
||||
TOCArticle.prototype.hasLocation = function() {
|
||||
return Boolean(this.filename);
|
||||
};
|
||||
|
||||
// Return true if has children
|
||||
TOCArticle.prototype.hasChildren = function() {
|
||||
return this.articles.length > 0;
|
||||
|
||||
+12
-2
@@ -168,6 +168,8 @@ Book.prototype.parse = function() {
|
||||
}
|
||||
|
||||
return Promise()
|
||||
|
||||
// Parse the readme
|
||||
.then(that.readme.load)
|
||||
.then(function() {
|
||||
if (that.readme.exists()) return;
|
||||
@@ -175,13 +177,21 @@ Book.prototype.parse = function() {
|
||||
throw new Error('No README file (or is ignored)');
|
||||
})
|
||||
|
||||
// Parse the summary
|
||||
.then(that.summary.load)
|
||||
.then(function() {
|
||||
if (that.summary.exists()) return;
|
||||
if (!that.summary.exists()) {
|
||||
throw new Error('No SUMMARY file (or is ignored)');
|
||||
}
|
||||
|
||||
throw new Error('No SUMMARY file (or is ignored)');
|
||||
// Index summary's articles
|
||||
that.summary.walk(function(article) {
|
||||
if (!article.hasLocation()) return;
|
||||
that.addPage(article.filename);
|
||||
});
|
||||
})
|
||||
|
||||
// Parse the glossary
|
||||
.then(that.glossary.load);
|
||||
});
|
||||
};
|
||||
|
||||
@@ -7,7 +7,7 @@ function JSONGenerator() {
|
||||
util.inherits(JSONGenerator, Generator);
|
||||
|
||||
// Write a page (parsable file)
|
||||
Generator.prototype.writePage = function(page) {
|
||||
JSONGenerator.prototype.writePage = function(page) {
|
||||
var json = {};
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,27 @@
|
||||
var util = require('util');
|
||||
var Generator = require('./base');
|
||||
|
||||
function WebsiteGenerator() {
|
||||
Generator.apply(this, arguments);
|
||||
}
|
||||
util.inherits(WebsiteGenerator, Generator);
|
||||
|
||||
// Copy an asset file
|
||||
WebsiteGenerator.prototype.writeAsset = function(filename) {
|
||||
var that = this;
|
||||
|
||||
return that.book.readFile(filename)
|
||||
.then(function(buf) {
|
||||
return that.output.writeFile(filename, buf);
|
||||
});
|
||||
};
|
||||
|
||||
// Write a page (parsable file)
|
||||
WebsiteGenerator.prototype.writePage = function(page) {
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
module.exports = WebsiteGenerator;
|
||||
+12
-2
@@ -1,6 +1,9 @@
|
||||
var _ = require('lodash');
|
||||
var fs = require('fs');
|
||||
var Ignore = require('ignore');
|
||||
|
||||
var Promise = require('./utils/promise');
|
||||
var pathUtil = require('./utils/path');
|
||||
var generators = require('./generators');
|
||||
var PluginsManager = require('./plugins');
|
||||
|
||||
@@ -24,9 +27,16 @@ function Output(book, type) {
|
||||
]);
|
||||
}
|
||||
|
||||
// Write a file to the output folder
|
||||
Output.prototype.writeFile = function(filename, buf) {
|
||||
|
||||
// Resolve a file in the output directory
|
||||
Output.prototype.resolve = function(filename) {
|
||||
return pathUtil.resolveInRoot.apply(null, [this.book.config.get('output')].concat(_.toArray(arguments)));
|
||||
};
|
||||
|
||||
// Write a file/buffer to the output folder
|
||||
Output.prototype.writeFile = function(filename, buf) {
|
||||
filename = this.resolve(filename);
|
||||
return Promise.nfcall(fs.writeFileSync, filename, buf);
|
||||
};
|
||||
|
||||
// Start the generation, for a parsed book
|
||||
|
||||
Reference in New Issue
Block a user