-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathgulpfile.js
More file actions
128 lines (112 loc) · 3.35 KB
/
Copy pathgulpfile.js
File metadata and controls
128 lines (112 loc) · 3.35 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
var gulp = require("gulp");
var htmlmin = require("gulp-htmlmin");
var uglify = require("gulp-uglify");
var minifyInline = require("gulp-minify-inline");
var pump = require("pump");
var historyApiFallback = require("connect-history-api-fallback");
var fileinclude = require("gulp-file-include");
var browserSync = require("browser-sync").create();
var del = require("del");
var plumber = require("gulp-plumber");
var fs = require("fs");
gulp.task("clean", function() {
return del(["dist/**", "src/html-compiled/**"]);
});
gulp.task("fileinclude", ["generateTalks"], function(callback) {
return gulp
.src(["src/html/*.html"])
.pipe(plumber())
.pipe(
fileinclude({
prefix: "@@",
basepath: "@file",
})
)
.pipe(gulp.dest("src/html-compiled/"))
.pipe(browserSync.stream());
});
gulp.task("dev-assets", ["clean"], function(callback) {
return gulp
.src(["src/imgs/**/*.*", "src/html/*.css", "src/*.pdf"])
.pipe(gulp.dest("src/html-compiled/"));
});
gulp.task("minify", ["fileinclude"], function() {
return gulp
.src("src/html-compiled/**/*.html")
.pipe(htmlmin({ collapseWhitespace: true, removeComments: true }))
.pipe(minifyInline())
.pipe(gulp.dest("dist"));
});
gulp.task("copy", function() {
return gulp
.src([
"src/_redirects",
"src/*.xml",
"src/*.txt",
"src/*.pdf",
"src/html/*.css",
"src/imgs/**",
])
.pipe(gulp.dest("dist"));
});
gulp.task("generateTalks", ["dev-assets"], () => {
const talks = require("./src/talks");
const template = fs.readFileSync("./src/html/_talkTemplate.html", {
encoding: "utf-8",
});
talks.forEach(talk => {
const { key, photoUrl, title, speaker, abstract, bio, workshop } = talk;
const content = template
.replace(/%photoUrl%/gi, photoUrl)
.replace(/%title%/gi, title)
.replace(/%speaker%/gi, speaker)
.replace(/%bio%/gi, bio.replace(/\n/g, "<br/><br/>"))
.replace(/%abstract%/gi, abstract.replace(/\n/g, "<br/><br/>"))
.replace(/%key%/gi, key)
.replace(/%session_type%/, (workshop?"Workshop":"Talk"));
fs.writeFileSync(`src/html/talk-${key}.html`, content, {
encoding: "utf-8",
});
});
});
gulp.task("build", ["fileinclude", "minify", "copy"]);
gulp.task("include-watch", ["fileinclude"], browserSync.reload);
gulp.task("watch", ["fileinclude", "browser-sync"], function() {
"use strict";
gulp.watch("./src/html/**/*.html", ["include-watch"]);
gulp.watch("./src/html/**/*.css", ["include-watch"]);
gulp.watch("./src/*.json", ["include-watch"]);
gulp.watch("./src/*.js", ["include-watch"]);
});
gulp.task("watch-dist", ["build"], function() {
"use strict";
gulp.watch("./dist/*.html", browserSync.reload);
});
function simpleURLRewrite(req, res, next) {
if (req.url === "/") {
req.url = "/index";
}
if (req.url.indexOf(".") === -1) {
req.url += ".html";
}
return next();
}
// Static server
gulp.task("browser-sync", ["fileinclude"], function() {
browserSync.init({
server: {
baseDir: "./src/html-compiled/",
},
middleware: simpleURLRewrite,
});
});
gulp.task("browser-sync-dist", ["build"], function() {
browserSync.init({
server: {
baseDir: "./dist/",
},
middleware: simpleURLRewrite,
});
});
gulp.task("default", ["dev-assets", "watch"]);
gulp.task("dist", ["watch-dist", "browser-sync-dist"]);