Permalink
Browse files

[minor] add reference to cache and catalog in constructor

  • Loading branch information...
1 parent dee3123 commit e1a2ba6313840cac3520709c150fca5b8f451b63 @Swaagie Swaagie committed Feb 24, 2014
Showing with 10 additions and 3 deletions.
  1. +10 −3 index.js
View
@@ -234,21 +234,28 @@ function walkSync(dir, result, sub) {
// event is not required thus easing the flow.
//
function Handbook() {
- var toc = walkSync(loc),
+ var toc = this.index = walkSync(loc),
+ cache = this.cache = {},
idx = this.idx = lunr(function setupLunr() {
this.field('title', { boost: 10 });
this.field('body');
});
Object.keys(toc).forEach(function loopSections(section) {
Object.keys(toc[section]).forEach(function loopPages(page) {
- var document = read((section !== 'index' ? section + '/' : '') + page);
+ var document = read((section !== 'index' ? section + '/' : '') + page)
+ , id = section + '/' + page;
idx.add({
- id: section + '/' + page,
+ id: id,
title: document.title,
body: document.content
});
+
+ //
+ // Keep cached reference of all documents, for quick external access.
+ //
+ cache[id] = document;
});
});
}

0 comments on commit e1a2ba6

Please sign in to comment.