diff options
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r-- | lib/generate/site/index.js | 56 |
1 files changed, 39 insertions, 17 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js index bf711d3..a8626a9 100644 --- a/lib/generate/site/index.js +++ b/lib/generate/site/index.js @@ -23,10 +23,36 @@ var Generator = function() { // Load base template this.template = swig.compileFile(path.resolve(this.options.theme, 'templates/site.html')); + this.langsTemplate = swig.compileFile(path.resolve(this.options.theme, 'templates/langs.html')); }; util.inherits(Generator, BaseGenerator); +// Generate a template +Generator.prototype._writeTemplate = function(tpl, options, output) { + var that = this; + return Q() + .then(function(sections) { + return tpl(_.extend({ + title: that.options.title, + description: that.options.description, + + githubAuthor: that.options.github.split("/")[0], + githubId: that.options.github, + githubHost: that.options.githubHost, + + summary: that.options.summary, + allNavigation: that.options.navigation + }, options)); + }) + .then(function(html) { + return fs.writeFile( + output, + html + ); + }); +}; + // Convert a markdown file to html Generator.prototype.convertFile = function(content, _input) { var that = this; @@ -47,16 +73,7 @@ Generator.prototype.convertFile = function(content, _input) { }); }) .then(function(sections) { - return that.template({ - title: that.options.title, - description: that.options.description, - - githubAuthor: that.options.github.split("/")[0], - githubId: that.options.github, - githubHost: that.options.githubHost, - - summary: that.options.summary, - allNavigation: that.options.navigation, + return that._writeTemplate(that.template, { progress: progress, _input: _input, @@ -64,16 +81,21 @@ Generator.prototype.convertFile = function(content, _input) { basePath: basePath, staticBase: path.join(basePath, "gitbook"), - }); - }) - .then(function(html) { - return fs.writeFile( - output, - html - ); + }, output); }); }; +// Generate languages index +Generator.prototype.langsIndex = function(langs) { + var basePath = "."; + return this._writeTemplate(this.langsTemplate, { + langs: langs.list, + + basePath: basePath, + staticBase: path.join(basePath, "gitbook"), + }, path.join(this.options.output, "index.html")); +}; + // Symlink index.html and copy assets Generator.prototype.finish = function() { var that = this; |