diff options
author | Samy Pesse <samypesse@gmail.com> | 2016-02-12 19:20:32 +0100 |
---|---|---|
committer | Samy Pesse <samypesse@gmail.com> | 2016-02-12 19:20:32 +0100 |
commit | 4555c541a8f98cb6ad4cbec2d7bf85b375dbf505 (patch) | |
tree | 0079507e1885a6c8a94a36644650a865f5e8cc5d /lib/page | |
parent | a853a51a0ba0976e8e28f368bd88717611b3c477 (diff) | |
download | gitbook-4555c541a8f98cb6ad4cbec2d7bf85b375dbf505.zip gitbook-4555c541a8f98cb6ad4cbec2d7bf85b375dbf505.tar.gz gitbook-4555c541a8f98cb6ad4cbec2d7bf85b375dbf505.tar.bz2 |
Replace links to page of summary by html links
Diffstat (limited to 'lib/page')
-rw-r--r-- | lib/page/index.js | 31 |
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); |