diff options
author | Samy Pessé <samypesse@gmail.com> | 2014-04-04 13:57:07 -0700 |
---|---|---|
committer | Samy Pessé <samypesse@gmail.com> | 2014-04-04 13:57:07 -0700 |
commit | 07101deaefb8848d40231eea12a3bf0710e6a78e (patch) | |
tree | f2b53bc8ae6dfe3bb0566f98fe40f426a7afec77 /lib/generate/site/index.js | |
parent | 76b3fcb41c1fc34c35b689148e12d83b7d924c92 (diff) | |
download | gitbook-07101deaefb8848d40231eea12a3bf0710e6a78e.zip gitbook-07101deaefb8848d40231eea12a3bf0710e6a78e.tar.gz gitbook-07101deaefb8848d40231eea12a3bf0710e6a78e.tar.bz2 |
Move generator to specific folder
Diffstat (limited to 'lib/generate/site/index.js')
-rw-r--r-- | lib/generate/site/index.js | 91 |
1 files changed, 91 insertions, 0 deletions
diff --git a/lib/generate/site/index.js b/lib/generate/site/index.js new file mode 100644 index 0000000..ac6ece6 --- /dev/null +++ b/lib/generate/site/index.js @@ -0,0 +1,91 @@ +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"); + +// Swig filter for returning the count of lines in a code section +swig.setFilter('lines', function(content) { + return content.split('\n').length; +}); + +// Swig filter for returning a link to the associated html file of a markdown file +swig.setFilter('mdLink', function(link) { + return link.replace(".md", ".html"); +}); + +var Generator = function() { + BaseGenerator.apply(this, arguments); + + // Load base template + this.template = swig.compileFile(path.resolve(__dirname, '../../templates/page.html')); +}; +util.inherits(Generator, BaseGenerator); + + +// 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) || "."; + + 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() { + var that = this; + + return fs.symlink( + 'README.html', + path.join(that.options.output, 'index.html') + ) + .then(function() { + return fs.copy( + path.join(__dirname, "../../assets/static"), + path.join(that.options.output, "gitbook") + ); + }); +}; + +module.exports = Generator;
\ No newline at end of file |