diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-04 10:39:27 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-04 10:39:27 -0700 |
commit | f656390783922952cc1f6fe8b0a5d0dc902fa92e (patch) | |
tree | 64ef14ca7a39560caaff47c1f202be320967443d | |
parent | 88c480ba4f59a77e448bb88ede36fca1470aca0c (diff) | |
download | gitbook-f656390783922952cc1f6fe8b0a5d0dc902fa92e.zip gitbook-f656390783922952cc1f6fe8b0a5d0dc902fa92e.tar.gz gitbook-f656390783922952cc1f6fe8b0a5d0dc902fa92e.tar.bz2 |
Base for new site generator
-rw-r--r-- | lib/generate/generator_site.js | 83 | ||||
-rw-r--r-- | lib/generate/index.js | 2 |
2 files changed, 70 insertions, 15 deletions
diff --git a/lib/generate/generator_site.js b/lib/generate/generator_site.js index 5d17b0c..1cc8614 100644 --- a/lib/generate/generator_site.js +++ b/lib/generate/generator_site.js @@ -1,32 +1,87 @@ -var BaseGenerator = require("./generator"); var util = require("util"); +var path = require("path"); +var Q = require("q"); +var swig = require('swig'); + +var fs = require("./fs"); +var parse = require("../parse"); +var BaseGenerator = require("./generator"); + +// Init swig filter lines for returning the count of lines in a code section +swig.setFilter('lines', function(content) { + return content.split('\n').length; +}); var Generator = function() { BaseGenerator.apply(this, arguments); + + // Load base template + this.template = swig.compileFile(path.resolve(__dirname, '../../templates/page.html')); }; util.inherits(Generator, BaseGenerator); -Generator.prototype.convertFile = function(input) { - console.log("convert file", input) + +// Convert a markdown file to html +Generator.prototype.convertFile = function(content, _input) { + var that = this; + var progress = parse.progress(this.options.navigation, _input); + + _output = _input.replace(".md", ".html"); + + var input = path.join(this.options.input, _input); + var output = path.join(this.options.output, _output); + var basePath = path.relative(path.dirname(output), this.options.output) || "."; + + console.log("Converting ", _input); + return Q() + .then(function() { + return parse.page(content, { + repo: that.options.githubId, + dir: path.dirname(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, + progress: progress, + + _input: _input, + content: sections, + + basePath: basePath, + staticBase: path.join(basePath, "gitbook"), + }); + }) + .then(function(html) { + return fs.writeFile( + output, + html + ); + }); }; +// Symlink index.html and copy assets Generator.prototype.finish = function() { - console.log("finish generation"); - // Symlink index.html to README.html - /*.then(function() { - return fs.symlink( - path.join(output, 'README.html'), - path.join(output, 'index.html') - ); - }) + var that = this; - // Copy assets + return fs.symlink( + path.join(that.options.output, 'README.html'), + path.join(that.options.output, 'index.html') + ) .then(function() { return fs.copy( path.join(__dirname, "../../assets/static"), - path.join(output, "gitbook") + path.join(that.options.output, "gitbook") ); - });*/ + }); }; module.exports = Generator;
\ No newline at end of file diff --git a/lib/generate/index.js b/lib/generate/index.js index 1606bd5..b6782f0 100644 --- a/lib/generate/index.js +++ b/lib/generate/index.js @@ -106,7 +106,7 @@ var generate = function(options) { }) .fail(function(err) { - console.log(err); + console.log(err.stack || err.message || err); return Q.reject(err); }) }; |