mirror of
https://github.com/GitbookIO/gitbook.git
synced 2026-09-20 17:43:24 +00:00
Remove file template.js
This commit is contained in:
@@ -5,7 +5,6 @@ var path = require("path");
|
||||
|
||||
var fs = require("./fs");
|
||||
var parse = require("../parse");
|
||||
var template = require("./template");
|
||||
|
||||
var generators = {
|
||||
"site": require("./generator_site"),
|
||||
|
||||
@@ -1,66 +0,0 @@
|
||||
var swig = require('swig');
|
||||
var path = require('path');
|
||||
var _ = require("lodash");
|
||||
|
||||
var parse = require("../parse");
|
||||
|
||||
var fs = require('./fs');
|
||||
|
||||
swig.setFilter('lines', function(content) {
|
||||
return content.split('\n').length;
|
||||
});
|
||||
|
||||
// return a templeter for page
|
||||
var initTemplate = function(options) {
|
||||
var tpl = swig.compileFile(path.resolve(__dirname, '../../templates/page.html'));
|
||||
|
||||
options = _.defaults(options || {}, {
|
||||
// Base folder for input
|
||||
root: "./",
|
||||
|
||||
// Base folder for output
|
||||
output: "./",
|
||||
|
||||
// Locals for templates
|
||||
locals: {}
|
||||
});
|
||||
|
||||
return function(input, output, local) {
|
||||
var _input = input, _output = output;
|
||||
input = path.join(options.root, input);
|
||||
output = path.join(options.output, output);
|
||||
|
||||
var basePath = path.relative(path.dirname(output), options.output) || ".";
|
||||
|
||||
// Read markdown file
|
||||
return fs.readFile(input, "utf-8")
|
||||
|
||||
// Parse sections
|
||||
.then(function(markdown) {
|
||||
return parse.page(markdown, {
|
||||
repo: options.locals.githubId,
|
||||
dir: path.dirname(_input) || '/'
|
||||
});
|
||||
})
|
||||
|
||||
//Calcul template
|
||||
.then(function(sections) {
|
||||
return tpl(
|
||||
_.extend(local || {}, options.locals, {
|
||||
_input: _input,
|
||||
content: sections,
|
||||
basePath: basePath,
|
||||
staticBase: path.join(basePath, "gitbook"),
|
||||
progress: parse.progress(options.locals.allNavigation, _output)
|
||||
})
|
||||
);
|
||||
})
|
||||
|
||||
// Write html
|
||||
.then(function(html) {
|
||||
return fs.writeFile(output, html);
|
||||
})
|
||||
}
|
||||
};
|
||||
|
||||
module.exports = initTemplate;
|
||||
Reference in New Issue
Block a user