Skip to content

Commit b4ad94e

Browse files
committed
Make contributor data available to hugo
1 parent 834c5f4 commit b4ad94e

File tree

4 files changed

+121
-260
lines changed

4 files changed

+121
-260
lines changed

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,5 @@ yarn-error.log
88
.vscode/
99
manifest.yml
1010
.imdone/
11-
11+
website/site/data/contributors.yml
1212
/coverage/

website/gulpfile.babel.js

+70-41
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
import gulp from "gulp";
22
import cp from "child_process";
3-
import hugoBin from "hugo-bin"
3+
import hugoBin from "hugo-bin";
44
import gutil from "gulp-util";
55
import postcss from "gulp-postcss";
6+
import transform from "gulp-transform";
7+
import yaml from "yamljs";
8+
import rename from "gulp-rename";
69
import cssImport from "postcss-import";
710
import neatgrid from "postcss-neat";
811
import nestedcss from "postcss-nested";
@@ -18,53 +21,94 @@ import webpackConfig from "./webpack.conf";
1821
const browserSync = BrowserSync.create();
1922
const defaultArgs = ["-d", "../dist", "-s", "site", "-v"];
2023

21-
gulp.task("hugo", (cb) => buildSite(cb));
22-
gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"]));
24+
function buildSite(cb, options) {
25+
const args = options ? defaultArgs.concat(options) : defaultArgs;
26+
return cp.spawn(hugoBin, args, { stdio: "inherit" }).on("close", code => {
27+
if (code === 0) {
28+
browserSync.reload();
29+
cb();
30+
} else {
31+
browserSync.notify("Hugo build failed :(");
32+
cb("Hugo build failed");
33+
}
34+
});
35+
}
36+
37+
gulp.task("hugo", ["copy"], cb => buildSite(cb));
38+
gulp.task("hugo-preview", ["copy"], cb =>
39+
buildSite(cb, ["--buildDrafts", "--buildFuture"])
40+
);
2341

2442
gulp.task("build", ["css", "js", "fonts", "images", "hugo"]);
2543
gulp.task("build-preview", ["css", "js", "fonts", "images", "hugo-preview"]);
2644

27-
gulp.task("css", () => (
28-
gulp.src("./src/css/**/*.css")
29-
.pipe(postcss([
30-
cssImport({from: "./src/css/main.css"}),
31-
neatgrid(),
32-
nestedcss(),
33-
colorfunctions(),
34-
hdBackgrounds(),
35-
cssextend(),
36-
cssvars({variables: styleVariables})]))
45+
gulp.task("css", () =>
46+
gulp
47+
.src("./src/css/**/*.css")
48+
.pipe(
49+
postcss([
50+
cssImport({ from: "./src/css/main.css" }),
51+
neatgrid(),
52+
nestedcss(),
53+
colorfunctions(),
54+
hdBackgrounds(),
55+
cssextend(),
56+
cssvars({ variables: styleVariables })
57+
])
58+
)
3759
.pipe(gulp.dest("./dist/css"))
3860
.pipe(browserSync.stream())
39-
));
61+
);
4062

41-
gulp.task("js", (cb) => {
63+
gulp.task("js", cb => {
4264
const myConfig = Object.assign({}, webpackConfig);
4365

4466
webpack(myConfig, (err, stats) => {
4567
if (err) throw new gutil.PluginError("webpack", err);
46-
gutil.log("[webpack]", stats.toString({
47-
colors: true,
48-
progress: true
49-
}));
68+
gutil.log(
69+
"[webpack]",
70+
stats.toString({
71+
colors: true,
72+
progress: true
73+
})
74+
);
5075
browserSync.reload();
5176
cb();
5277
});
5378
});
5479

55-
gulp.task("fonts", () => (
56-
gulp.src("./src/fonts/**/*")
80+
gulp.task("fonts", () =>
81+
gulp
82+
.src("./src/fonts/**/*")
5783
.pipe(gulp.dest("./dist/fonts"))
5884
.pipe(browserSync.stream())
59-
));
85+
);
6086

61-
gulp.task("images", () => (
62-
gulp.src("./src/img/**/*")
87+
gulp.task("images", () =>
88+
gulp
89+
.src("./src/img/**/*")
6390
.pipe(gulp.dest("./dist/img"))
6491
.pipe(browserSync.stream())
65-
));
92+
);
93+
94+
gulp.task("copy", () =>
95+
gulp
96+
.src("../.all-contributorsrc")
97+
.pipe(
98+
transform(
99+
"utf8",
100+
content =>
101+
new Promise((resolve, reject) => {
102+
const contributors = JSON.parse(content);
103+
resolve(yaml.dump({ contributors: contributors.contributors }));
104+
})
105+
)
106+
)
107+
.pipe(rename("contributors.yml"))
108+
.pipe(gulp.dest("./site/data"))
109+
);
66110

67-
gulp.task("server", ["hugo", "css", "js", "fonts", "images"], () => {
111+
gulp.task("server", ["css", "js", "fonts", "images", "hugo"], () => {
68112
browserSync.init({
69113
server: {
70114
baseDir: "./dist"
@@ -77,18 +121,3 @@ gulp.task("server", ["hugo", "css", "js", "fonts", "images"], () => {
77121
gulp.watch("./src/fonts/**/*", ["fonts"]);
78122
gulp.watch("./site/**/*", ["hugo"]);
79123
});
80-
81-
function buildSite(cb, options) {
82-
const args = options ? defaultArgs.concat(options) : defaultArgs;
83-
84-
return cp.spawn(hugoBin, args, {stdio: "inherit"}).on("close", (code) => {
85-
if (code === 0) {
86-
browserSync.reload();
87-
cb();
88-
} else {
89-
browserSync.notify("Hugo build failed :(");
90-
cb("Hugo build failed");
91-
}
92-
});
93-
}
94-

website/package.json

+2
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@
3232
"gulp": "^3.9.1",
3333
"gulp-babel": "^6.1.2",
3434
"gulp-postcss": "^6.1.1",
35+
"gulp-rename": "^1.2.2",
36+
"gulp-transform": "^3.0.5",
3537
"gulp-util": "^3.0.7",
3638
"hugo-bin": "^0.18.0",
3739
"imports-loader": "^0.6.5",

0 commit comments

Comments
 (0)