-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgulpfile.js
114 lines (90 loc) · 3.09 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
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
const fs = require("fs");
const nunjucks = require("nunjucks");
const gulp = require("gulp");
const data = require("gulp-data");
const less = require("gulp-less");
const nunjucksRender = require("gulp-nunjucks-render");
const CONTENT_FILES = ["articles", "projects", "work", "education", "honors", "publications"];
const SKILLS = ["design", "usability/UX", "research", "computer science", "management", "AR/VR",
"analytics", "machine learning", "startup", "ringtennis"];
function compare(a,b) {
if (a.dateInt < b.dateInt)
return +1;
if (a.dateInt > b.dateInt)
return -1;
return 0;
}
/**
* @unused
* de-caching for data files
* from: https://github.com/colynb/gulp-data/issues/17
*/
function requireUncached($module) {
delete require.cache[require.resolve($module)];
return require($module);
}
gulp.task("less", function() {
return gulp.src(["css/day.less", "css/night.less"])
.pipe(less())
.pipe(gulp.dest("css"));
});
gulp.task("nunjucks", function() {
const content = {
categories: {},
skills: {}
};
const skillsTemp = {};
for (let i=0; i<SKILLS.length; ++i) {
content.skills[SKILLS[i]] = [];
skillsTemp[SKILLS[i]] = [];
}
content.skills.other = [];
skillsTemp.other = [];
for (let i=0; i<CONTENT_FILES.length; ++i) {
const rawData = fs.readFileSync("assets/" + CONTENT_FILES[i] + ".json", "utf8");
const jsonData = JSON.parse(rawData);
const template = fs.readFileSync("assets/" + CONTENT_FILES[i] + ".nunjucks", "utf8");
content.categories[jsonData.title] = [];
for (let j=0; j<jsonData.entries.length; ++j) {
const entryCategory = nunjucks.renderString(template, jsonData.entries[j]);
const entrySkill = nunjucks.renderString(template, Object.assign({ category: jsonData.title }, jsonData.entries[j]));
const tags = jsonData.entries[j].tags;
content.categories[jsonData.title].push(entryCategory);
let added = false;
for (let k=0; k<tags.length; ++k) {
if (skillsTemp[tags[k]]) {
skillsTemp[tags[k]].push({ dateInt: jsonData.entries[j].dateInt, entry: entrySkill });
added = true;
}
}
if (!added) {
skillsTemp.other.push({ dateInt: jsonData.entries[j].dateInt, entry: entrySkill });
}
}
}
for (let i=0; i<SKILLS.length; ++i) {
skillsTemp[SKILLS[i]].sort(compare);
for (let j=0; j<skillsTemp[SKILLS[i]].length; ++j) {
content.skills[SKILLS[i]].push(skillsTemp[SKILLS[i]][j].entry);
}
}
skillsTemp.other.sort(compare);
for (let i=0; i<skillsTemp.other.length; ++i) {
content.skills.other.push(skillsTemp.other[i].entry);
}
return gulp.src("index.nunjucks")
.pipe(data(function() {
return {
categories: CONTENT_FILES,
skills: SKILLS,
content: content
};
}))
.pipe(nunjucksRender())
.pipe(gulp.dest("."));
});
gulp.task("watch", function() {
gulp.watch("css/*.less", ["less"]);
gulp.watch(["index.nunjucks", "assets/*.json", "assets/*.nunjucks"], ["nunjucks"]);
});
gulp.task("default", ["watch", "less", "nunjucks"]);