diff options
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r-- | lib/generate/site/index.js | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index 588ffdb..0bd2318 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -188,7 +188,36 @@ Generator.prototype.writeGlossary = function() { var that = this; var basePath = "."; + // No glossary + if (!this.glossaryIndexer) return Q(); + + // Transform the glossary to get term, description, files + var glossary = _.chain(this.glossaryIndexer.invertedIdx) + .map(function(links, id) { + var term = _.find(that.options.glossary, { 'id': id }); + + return { + id: id, + name: term.name, + description: term.description, + files: _.chain(links) + .map(function(link) { + var name = link.slice(0, -5); + + if (name == "index") { + name = "README"; + } + return that.options.navigation[name+".md"]; + }) + .sortBy("percent") + .value() + } + }) + .sortBy("name") + .value(); + return this._writeTemplate(this.glossaryTemplate, { + glossaryIndex: glossary, basePath: basePath, staticBase: path.join(basePath, "gitbook"), }, path.join(this.options.output, "GLOSSARY.html")); @@ -223,11 +252,22 @@ Generator.prototype.writeSearchIndex = function() { ); }; +// Dump glossary index to disk +Generator.prototype.writeGlossaryIndex = function() { + if (!this.glossaryIndexer) return Q(); + + return fs.writeFile( + path.join(this.options.output, 'glossary_index.json'), + JSON.stringify(this.options.glossary) + ); +}; + Generator.prototype.finish = function() { return this.copyAssets() .then(this.copyCover) .then(this.writeGlossary) + .then(this.writeGlossaryIndex) .then(this.writeSearchIndex); }; |