Commit 4c821c92 authored by Simon Bartlett's avatar Simon Bartlett

Extracted getData method

parent 78cdba60
...@@ -33,6 +33,35 @@ var readIndexYml = function() { ...@@ -33,6 +33,35 @@ var readIndexYml = function() {
return yaml.safeLoad(fs.readFileSync('./source/index.yml', 'utf8')); return yaml.safeLoad(fs.readFileSync('./source/index.yml', 'utf8'));
}; };
var getPageData = function() {
var config = readIndexYml();
var includes = config.includes
.map(function(include) { return './source/includes/' + include + '.md'; })
.map(function(include) { return fs.readFileSync(include, 'utf8'); })
.map(function(include) { return marked(include, { renderer: renderer }); });
return {
current_page: {
data: config
},
page_classes: '',
includes: includes,
image_tag: function(filename, alt, className) {
return '<img alt="' + alt + '" class="' + className + '" src="images/' + filename + '">';
},
javascript_include_tag: function(name) {
return '<script src="javascripts/' + name + '.js" type="text/javascript"></script>';
},
stylesheet_link_tag: function(name, media) {
return '<link href="stylesheets/' + name + '.css" rel="stylesheet" type="text/css" media="' + media + '" />';
},
langs: (config.language_tabs || []).map(function(lang) {
return typeof lang == 'string' ? lang : lang.keys.first;
})
};
};
gulp.task('clean', function () { gulp.task('clean', function () {
return del(['build/*']); return del(['build/*']);
}); });
...@@ -89,32 +118,7 @@ gulp.task('highlightjs', function () { ...@@ -89,32 +118,7 @@ gulp.task('highlightjs', function () {
}); });
gulp.task('html', function () { gulp.task('html', function () {
var config = readIndexYml(); var data = getPageData();
var includes = config.includes
.map(function(include) { return './source/includes/' + include + '.md'; })
.map(function(include) { return fs.readFileSync(include, 'utf8'); })
.map(function(include) { return marked(include, { renderer: renderer }); });
var data = {
current_page: {
data: config
},
page_classes: '',
includes: includes,
image_tag: function(filename) {
return '<img src="images/' + filename + '">';
},
javascript_include_tag: function(name) {
return '<script src="javascripts/' + name + '.js" type="text/javascript"></script>';
},
stylesheet_link_tag: function(name, media) {
return '<link href="stylesheets/' + name + '.css" rel="stylesheet" type="text/css" media="' + media + '" />';
},
langs: (config.language_tabs || []).map(function(lang) {
return typeof lang == 'string' ? lang : lang.keys.first;
})
};
return gulp.src('./source/*.html') return gulp.src('./source/*.html')
.pipe(ejs(data).on('error', gutil.log)) .pipe(ejs(data).on('error', gutil.log))
.pipe(gulpif(COMPRESS, prettify({indent_size: 2}))) .pipe(gulpif(COMPRESS, prettify({indent_size: 2})))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment