diff options
author | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-08-19 16:09:47 -0700 |
---|---|---|
committer | Aaron O'Mullan <aaron.omullan@gmail.com> | 2014-08-19 16:09:47 -0700 |
commit | 71aff100921f7fcf94c9d75e0bd17c4fcb4669b6 (patch) | |
tree | cfefdd61394268bd6f4255eff7414c8a03460c3a /lib/generate/site/index.js | |
parent | f77404afe180e97692897237dca7598eae33a761 (diff) | |
parent | 4b390667e574ab46842821f029f3941d797a8b1a (diff) | |
download | gitbook-71aff100921f7fcf94c9d75e0bd17c4fcb4669b6.zip gitbook-71aff100921f7fcf94c9d75e0bd17c4fcb4669b6.tar.gz gitbook-71aff100921f7fcf94c9d75e0bd17c4fcb4669b6.tar.bz2 |
Merge pull request #413 from GitbookIO/feature/glossary
Glossary terms highlight in page
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); }; |