Answer the question
In order to leave comments, you need to log in
Optimizing specific JS code (gulp)?
Hello. Sorry for the question, which asks you to write more code for TCa, but I don’t know how to do it ..
In general, the logic of gulp.js is this:
There are files in 3 folders ./haml/p; ./haml/l; ./haml/i
These contain .haml files. Next, you need to collect these files into the appropriate ./_p ; ./_l ; ./_i directories, but it collects them in one line. I decided to apply prettify for html in addition to everything. In my code below, we save each haml file first to ./haml/html/(p|l|i) and then prettify to the correct directory.
Ideally, everything should be done in two tasks, but I can't figure out how to do it. Here is the code that works:
var gulp = require('gulp');
var haml = require('gulp-haml');
var prettify = require('gulp-prettify');
gulp.task('layouts', function() {
gulp.src('./haml/layouts/*.haml')
.pipe(haml())
.pipe(gulp.dest('./haml/html/_layouts/'));
});
gulp.task('prettify_layouts', function(){
gulp.src('./haml/html/_layouts/*.html')
.pipe(prettify({indent_size: 2}))
.pipe(gulp.dest('./_layouts/'));
});
gulp.task('includes', function() {
gulp.src('./haml/includes/*.haml')
.pipe(haml())
.pipe(gulp.dest('./haml/html/_includes/'));
});
gulp.task('prettify_includes', function(){
gulp.src('./haml/html/_includes/*.html')
.pipe(prettify({indent_size: 2}))
.pipe(gulp.dest('./_includes/'));
});
gulp.task('posts', function() {
gulp.src('./haml/posts/*.haml')
.pipe(haml())
.pipe(gulp.dest('./haml/html/_posts/'));
});
gulp.task('prettify_posts', function(){
gulp.src('./haml/html/_posts/*.html')
.pipe(prettify({indent_size: 2}))
.pipe(gulp.dest('./_posts/'));
});
gulp.task('default', function() {
gulp.start('includes','prettify_includes', 'layouts', 'prettify_layouts', 'posts', 'prettify_posts');
});
Answer the question
In order to leave comments, you need to log in
What does not suit you in the following code (the option can be improved if you understand where to go):
var gulp = require('gulp');
var haml = require('gulp-haml');
var prettify = require('gulp-prettify');
gulp.task('layouts', function() {
gulp.src('./haml/layouts/*.haml')
.pipe(haml())
.pipe(prettify({indent_size: 2}))
.pipe(gulp.dest('./_layouts/'));
});
gulp.task('includes', function() {
gulp.src('./haml/includes/*.haml')
.pipe(haml())
.pipe(prettify({indent_size: 2}))
.pipe(gulp.dest('./_includes/'));
});
gulp.task('posts', function() {
gulp.src('./haml/posts/*.haml')
.pipe(haml())
.pipe(prettify({indent_size: 2}))
.pipe(gulp.dest('./_posts/'));
});
gulp.task('default', ['includes', 'layouts', 'posts']);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question