summaryrefslogtreecommitdiffstats
path: root/lib/page
diff options
context:
space:
mode:
Diffstat (limited to 'lib/page')
-rw-r--r--lib/page/index.js31
1 files changed, 26 insertions, 5 deletions
diff --git a/lib/page/index.js b/lib/page/index.js
index e7a4fec..711e0e1 100644
--- a/lib/page/index.js
+++ b/lib/page/index.js
@@ -3,6 +3,7 @@ var path = require('path');
var parsers = require('gitbook-parsers');
var error = require('../utils/error');
+var pathUtil = require('../utils/path');
var HTMLPipeline = require('./html');
/*
@@ -40,10 +41,25 @@ function Page(book, filename) {
// Return the filename of the page with another extension
// "README.md" -> "README.html"
Page.prototype.withExtension = function(ext) {
- return path.join(
- path.dirname(this.path),
- path.basename(this.path, path.extname(this.path)) + ext
- );
+ return pathUtil.setExtension(this.path, ext);
+};
+
+// Filename for output
+// READMEs are replaced by index.html
+Page.prototype.outputPath = function(ext) {
+ ext = ext || '.html';
+ var output;
+
+ if (
+ path.basename(this.path, path.extname(this.path)) == 'README' ||
+ output == this.book.readme.path
+ ) {
+ output = path.join(path.dirname(output), 'index'+ext);
+ } else {
+ output = pathUtil.setExtension(output, ext);
+ }
+
+ return output;
};
// Update content of the page
@@ -107,8 +123,13 @@ Page.prototype.parse = function(opts) {
// Normalize HTML output
.then(function() {
var pipelineOpts = _.extend({
+
+ // Replace links to page of summary
onRelativeLink: function(href) {
- console.log('href', href);
+ var to = that.book.getPage(href);
+ if (to) return to.outputPath();
+
+ return href;
}
}, opts);
var pipeline = new HTMLPipeline(that.content, pipelineOpts);