summaryrefslogtreecommitdiffstats
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
parentbd931c5cbdced15701a9bba4806350dedc359221 (diff)
downloadgitbook-3c605ea8099bcba58d8eeb0435d87c563d434e46.zip
gitbook-3c605ea8099bcba58d8eeb0435d87c563d434e46.tar.gz
gitbook-3c605ea8099bcba58d8eeb0435d87c563d434e46.tar.bz2
generate an index.html for entry points
-rw-r--r--README.md1
-rw-r--r--lib/generators/site.js22
-rw-r--r--test/generation.js1
3 files changed, 19 insertions, 5 deletions
diff --git a/README.md b/README.md
index f2f3533..2281657 100644
--- a/README.md
+++ b/README.md
@@ -10,3 +10,4 @@ ChangeLog with 1.0.0:
- Exercises and Quizzes are no longer parsed in the markdown parser
- You can now also use the `.markdown` extension for markdown files
- Templates are rendered with nunjucks instead of swig, syntax is almost compatible, there is some changes with contexts and filters.
+- `{{ super() }}` should be use instead of `{% parent %}`
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)
diff --git a/test/generation.js b/test/generation.js
index c2c8094..d2d0574 100644
--- a/test/generation.js
+++ b/test/generation.js
@@ -51,7 +51,6 @@ describe('Book generation', function () {
it('should correctly generate a book to website', function(done) {
testGeneration(book1, "site", function(output) {
- console.log(fs.readdirSync(output));
assert(fs.existsSync(path.join(output, "index.html")));
}, done);
});