forked from justdeleteme/justdelete.me
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gulpfile.js
56 lines (46 loc) · 1.66 KB
/
gulpfile.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
var gulp = require('gulp'),
fs = require('fs'),
rename = require('gulp-rename'),
del = require('del'),
swig = require('gulp-swig'),
data = require('gulp-data')
jsonlint = require('gulp-jsonlint');
var translations = JSON.parse(fs.readFileSync('_trans/_config.json')),
rtl = ['fa', 'ar'],
sites,
trans,
notes;
gulp.task('jsonlint', function() {
gulp.src('sites.json')
.pipe(jsonlint())
.pipe(jsonlint.reporter());
});
gulp.task('clean', function(callback) {
return del(['docs/*.html'], callback);
});
gulp.task('translate', ['clean'], function() {
translations.forEach(function(translation) {
sites = JSON.parse(fs.readFileSync('sites.json'));
trans = JSON.parse(fs.readFileSync('_trans/' + translation.code + '.json'));
if (translation.code !== 'en') {
sites.forEach(function(site, i) {
if (site.notes) {
site.notes = site['notes_'+translation.code] ? site['notes_'+translation.code] : site.notes;
sites[i] = site;
}
});
}
gulp.src('template.html')
.pipe(rename((translation.code == 'en' ? 'index' : translation.code) + '.html'))
.pipe(data({
trans: translation,
i18n: trans,
sites: sites,
rtl: (rtl.indexOf(translation.code) == -1) ? false : true,
assetPath: 'assets'
}))
.pipe(swig())
.pipe(gulp.dest('docs'));
});
});
gulp.task('default', ['jsonlint', 'translate']);