summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/output/base.js25
-rw-r--r--lib/output/website.js19
-rw-r--r--lib/page/index.js18
3 files changed, 42 insertions, 20 deletions
diff --git a/lib/output/base.js b/lib/output/base.js
index 638ee25..a6cfa0d 100644
--- a/lib/output/base.js
+++ b/lib/output/base.js
@@ -3,6 +3,7 @@ var Ignore = require('ignore');
var path = require('path');
var Promise = require('../utils/promise');
+var pathUtil = require('../utils/path');
var PluginsManager = require('../plugins');
var TemplateEngine = require('../template');
var gitbook = require('../gitbook');
@@ -30,6 +31,9 @@ function Output(book) {
this.ignore = Ignore();
}
+// Default extension for output
+Output.prototype.defaultExtension = '.html';
+
// Start the generation, for a parsed book
Output.prototype.generate = function() {
var that = this;
@@ -126,7 +130,7 @@ Output.prototype.finish = function() {
// Resolve an HTML link
Output.prototype.onRelativeLink = function(currentPage, href) {
var to = this.book.getPage(href);
- if (to) return to.outputPath();
+ if (to) return this.outputPath(to.path);
return href;
};
@@ -166,4 +170,23 @@ Output.prototype.getPageContext = function(page) {
);
};
+
+// Filename for output
+// READMEs are replaced by index.html
+Output.prototype.outputPath = function(filename, ext) {
+ ext = ext || this.defaultExtension;
+ var output;
+
+ if (
+ path.basename(filename, path.extname(filename)) == 'README' ||
+ output == this.book.readme.path
+ ) {
+ output = path.join(path.dirname(output), 'index'+ext);
+ } else {
+ output = pathUtil.setExtension(output, ext);
+ }
+
+ return output;
+};
+
module.exports = Output;
diff --git a/lib/output/website.js b/lib/output/website.js
index 41395e6..e25240c 100644
--- a/lib/output/website.js
+++ b/lib/output/website.js
@@ -63,6 +63,23 @@ WebsiteOutput.prototype.prepare = function() {
.value();
that.env = new nunjucks.Environment(new nunjucks.FileSystemLoader(searchPaths));
+
+ that.env.addGlobal('__', function(s) {
+ // todo: i18n
+ return s;
+ });
+
+ // Transform an absolute path into a relative path
+ // using this.ctx.page.path
+ that.env.addFilter('resolveFile', function(s) {
+ // todo
+ return s;
+ });
+
+ // Transform a '.md' into a '.html' (README -> index)
+ that.env.addFilter('contentURL', function(s) {
+ return that.outputPath(s);
+ });
});
};
@@ -76,7 +93,7 @@ WebsiteOutput.prototype.onPage = function(page) {
// Write the HTML file
.then(function(html) {
return that.writeFile(
- page.withExtension('.html'),
+ that.outputPath(page.path),
html
);
});
diff --git a/lib/page/index.js b/lib/page/index.js
index 6dcefa1..c9cd066 100644
--- a/lib/page/index.js
+++ b/lib/page/index.js
@@ -45,24 +45,6 @@ Page.prototype.withExtension = function(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;
-};
-
// Resolve a filename relative to this page
// It returns a path relative to the book root folder
Page.prototype.resolveLocal = function() {