summaryrefslogtreecommitdiffstats
path: root/lib/generators
diff options
context:
space:
mode:
authorSamy Pessé <samypesse@gmail.com>2015-01-21 19:40:40 +0100
committerSamy Pessé <samypesse@gmail.com>2015-01-21 19:40:40 +0100
commit3c605ea8099bcba58d8eeb0435d87c563d434e46 (patch)
tree55b18700bef50dab165bf63dab7a4292918e7821 /lib/generators
parentbd931c5cbdced15701a9bba4806350dedc359221 (diff)
downloadgitbook-3c605ea8099bcba58d8eeb0435d87c563d434e46.zip
gitbook-3c605ea8099bcba58d8eeb0435d87c563d434e46.tar.gz
gitbook-3c605ea8099bcba58d8eeb0435d87c563d434e46.tar.bz2
generate an index.html for entry points
Diffstat (limited to 'lib/generators')
-rw-r--r--lib/generators/site.js22
1 files changed, 18 insertions, 4 deletions
diff --git a/lib/generators/site.js b/lib/generators/site.js
index a19da25..cd63bbe 100644
--- a/lib/generators/site.js
+++ b/lib/generators/site.js
@@ -59,7 +59,7 @@ Generator.prototype.prepareStyles = function() {
Generator.prototype.prepareTemplates = function() {
this.pageTemplate = this.plugins.template("site:page") || path.resolve(this.templatesRoot, 'page.html');
this.langsTemplate = this.plugins.template("site:langs") || path.resolve(this.templatesRoot, 'langs.html');
- this.glossaryTemplate = this.plugins.template("site:glossary") || path.resolve(this.templatesRoot, 'templates/website/glossary.html');
+ this.glossaryTemplate = this.plugins.template("site:glossary") || path.resolve(this.templatesRoot, 'glossary.html');
var folders = _.chain(
[
@@ -69,8 +69,6 @@ Generator.prototype.prepareTemplates = function() {
.uniq()
.value();
- console.log("templates folders", folders)
-
this.env = new nunjucks.Environment(
new nunjucks.FileSystemLoader(folders),
{
@@ -78,6 +76,9 @@ Generator.prototype.prepareTemplates = function() {
}
);
+ // Add filter
+ this.env.addFilter("contentLink", this.contentLink.bind(this));
+
// Add extension
this.env.addExtension('ParentExtension', new ParentExtension());
this.env.addExtension('AutoEscapeExtension', new AutoEscapeExtension(this.env));
@@ -96,11 +97,24 @@ Generator.prototype.finish = function() {
};
+// Normalize a link to .html and convert README -> index
+Generator.prototype.contentLink = function(link) {
+ if (
+ path.basename(link) == "README"
+ || link == this.book.readmeFile
+ ) {
+ link = path.join(path.dirname(link), "index"+path.extname(link));
+ }
+
+ link = links.changeExtension(link, ".html");
+ return link;
+}
+
// Convert an input file
Generator.prototype.writeParsedFile = function(page) {
var that = this;
- var output = links.changeExtension(page.path, ".html");
+ var output = this.contentLink(page.path);
output = path.join(that.options.output, output);
return that.normalizePage(page)