From 6e83240233e6168aa6567eb6fcac62508fe7fd0e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Samy=20Pess=C3=A9?= Date: Thu, 18 Feb 2016 13:58:10 +0100 Subject: [PATCH] Glossary should be output as a normal page --- lib/backbone/glossary.js | 21 +++++++++++++++++++++ lib/output/base.js | 1 + lib/page/html.js | 2 +- lib/page/index.js | 9 +-------- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/lib/backbone/glossary.js b/lib/backbone/glossary.js index 9aed1ac35..45848e0ae 100644 --- a/lib/backbone/glossary.js +++ b/lib/backbone/glossary.js @@ -44,6 +44,15 @@ util.inherits(Glossary, BackboneFile); Glossary.prototype.type = 'glossary'; +// Get templating context +Glossary.prototype.getContext = function() { + return { + glossary: { + path: this.path + } + }; +}; + // Parse the readme content Glossary.prototype.parse = function(content) { var that = this; @@ -73,4 +82,16 @@ Glossary.prototype.isEmpty = function(id) { return _.size(this.entries) === 0; }; +// Convert the glossary to a list of annotations +Glossary.prototype.annotations = function() { + return _.map(this.entries, function(entry) { + return { + id: entry.id, + name: entry.name, + description: entry.description, + href: '/' + this.path + '#' + entry.id + }; + }, this); +}; + module.exports = Glossary; diff --git a/lib/output/base.js b/lib/output/base.js index 09f57bc38..d22fda1eb 100644 --- a/lib/output/base.js +++ b/lib/output/base.js @@ -169,6 +169,7 @@ Output.prototype.getPageContext = function(page) { gitbook.getContext(), this.book.getContext(), this.book.summary.getContext(), + this.book.glossary.getContext(), this.book.config.getContext() ); }; diff --git a/lib/page/html.js b/lib/page/html.js index d667059d9..45fae0d7c 100644 --- a/lib/page/html.js +++ b/lib/page/html.js @@ -164,7 +164,7 @@ HTMLPipeline.prototype.applyAnnotations = function() { replaceText(that.$, this, searchRegex, function(match) { that.opts.onAnnotation(annotation); - return '' + match + ''; diff --git a/lib/page/index.js b/lib/page/index.js index 51ed2aa53..bdf3c81b4 100644 --- a/lib/page/index.js +++ b/lib/page/index.js @@ -166,14 +166,7 @@ Page.prototype.toHTML = function(output) { }, // Convert glossary entries to annotations - annotations: _.map(that.book.glossary.entries, function(entry) { - return { - id: entry.id, - name: entry.name, - description: entry.description, - href: '/GLOSSARY.html' - }; - }) + annotations: that.book.glosary.annotations() }; var pipeline = new HTMLPipeline(that.content, pipelineOpts);