summaryrefslogtreecommitdiffstats
path: root/lib/generate/site/index.js
diff options
context:
space:
mode:
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r--lib/generate/site/index.js67
1 files changed, 48 insertions, 19 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js
index bf711d3..9c3c10c 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,18 +81,29 @@ 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 that = this;
+ var basePath = ".";
+
+ return this._writeTemplate(this.langsTemplate, {
+ langs: langs.list,
+
+ basePath: basePath,
+ staticBase: path.join(basePath, "gitbook"),
+ }, path.join(this.options.output, "index.html"))
+ .then(function() {
+ // Copy assets
+ return that.copyAssets();
});
};
-// Symlink index.html and copy assets
-Generator.prototype.finish = function() {
+// Copy assets
+Generator.prototype.copyAssets = function() {
var that = this;
return fs.copy(
@@ -83,5 +111,6 @@ Generator.prototype.finish = function() {
path.join(that.options.output, "gitbook")
);
};
+Generator.prototype.finish = Generator.prototype.copyAssets;
module.exports = Generator; \ No newline at end of file