summaryrefslogtreecommitdiffstats
path: root/lib/generate/site
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generate/site')
-rw-r--r--lib/generate/site/glossary_indexer.js9
-rw-r--r--lib/generate/site/index.js40
2 files changed, 44 insertions, 5 deletions
diff --git a/lib/generate/site/glossary_indexer.js b/lib/generate/site/glossary_indexer.js
index d46e393..dc9c2d8 100644
--- a/lib/generate/site/glossary_indexer.js
+++ b/lib/generate/site/glossary_indexer.js
@@ -28,9 +28,6 @@ function Indexer(glossary) {
"gi"
);
- // debug
- console.log('term regex =', this.termsRegex);
-
// page url => terms
this.idx = {
/*
@@ -66,8 +63,6 @@ Indexer.prototype.text = function(nodes) {
// Add page to glossary index
Indexer.prototype.add = function(sections, url) {
if(!(this.glossary && this.glossary.length > 0)) {
- console.log('Glossary =', this.glossary);
- console.log('No glossary to match');
return;
}
@@ -93,6 +88,10 @@ Indexer.prototype.add = function(sections, url) {
}.bind(this));
};
+// Dump index as a string
+Indexer.prototype.dump = function() {
+ return JSON.stringify(this.idx);
+};
function regexEscape(s) {
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);
};