diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-08-18 21:53:07 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-08-18 21:53:07 -0700 |
commit | 6f1ef585bec7e169aacbd0c0116472334e1145c7 (patch) | |
tree | 14f19c07d58423c759659e8f23185adb27306983 | |
parent | d84acd0b82bb3cffa94d3ad591d99064efb45b7a (diff) | |
download | gitbook-6f1ef585bec7e169aacbd0c0116472334e1145c7.zip gitbook-6f1ef585bec7e169aacbd0c0116472334e1145c7.tar.gz gitbook-6f1ef585bec7e169aacbd0c0116472334e1145c7.tar.bz2 |
Show index on glossary page
-rw-r--r-- | lib/generate/site/glossary_indexer.js | 2 | ||||
-rw-r--r-- | lib/generate/site/index.js | 29 | ||||
-rw-r--r-- | theme/templates/glossary.html | 10 |
3 files changed, 38 insertions, 3 deletions
diff --git a/lib/generate/site/glossary_indexer.js b/lib/generate/site/glossary_indexer.js index da653c8..dc9c2d8 100644 --- a/lib/generate/site/glossary_indexer.js +++ b/lib/generate/site/glossary_indexer.js @@ -88,7 +88,7 @@ Indexer.prototype.add = function(sections, url) { }.bind(this)); }; - +// Dump index as a string Indexer.prototype.dump = function() { return JSON.stringify(this.idx); }; diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index af8711b..953522c 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")); diff --git a/theme/templates/glossary.html b/theme/templates/glossary.html index 539ec59..315d354 100644 --- a/theme/templates/glossary.html +++ b/theme/templates/glossary.html @@ -3,10 +3,16 @@ {% block title %}Glossary | {{ title }}{% endblock %} {% block page_inner %} -{% for item in glossary %} -<section class="normal glossary" id="{{ item.name }}"> +{% for item in glossaryIndex %} +<section class="normal glossary" id="{{ item.id }}"> <h2>{{ item.name }}</h2> <p>{{ item.description }}</p> + <h4>Index</h4> + <ul class="glossary-index"> + {% for file in item.files %} + <li><a href="{{ basePath }}/{{ file.path|mdLink }}">{{ file.title }}</a></li> + {% endfor %} + </ul> </section> {% endfor %} {% endblock %} |