Skip to content

Commit

Permalink
Make contributor data available to hugo
Browse files Browse the repository at this point in the history
  • Loading branch information
imorente committed Dec 7, 2017
1 parent 834c5f4 commit b4ad94e
Show file tree
Hide file tree
Showing 4 changed files with 121 additions and 260 deletions.
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ yarn-error.log
.vscode/
manifest.yml
.imdone/

website/site/data/contributors.yml
/coverage/
111 changes: 70 additions & 41 deletions website/gulpfile.babel.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import gulp from "gulp";
import cp from "child_process";
import hugoBin from "hugo-bin"
import hugoBin from "hugo-bin";
import gutil from "gulp-util";
import postcss from "gulp-postcss";
import transform from "gulp-transform";
import yaml from "yamljs";
import rename from "gulp-rename";
import cssImport from "postcss-import";
import neatgrid from "postcss-neat";
import nestedcss from "postcss-nested";
Expand All @@ -18,53 +21,94 @@ import webpackConfig from "./webpack.conf";
const browserSync = BrowserSync.create();
const defaultArgs = ["-d", "../dist", "-s", "site", "-v"];

gulp.task("hugo", (cb) => buildSite(cb));
gulp.task("hugo-preview", (cb) => buildSite(cb, ["--buildDrafts", "--buildFuture"]));
function buildSite(cb, options) {
const args = options ? defaultArgs.concat(options) : defaultArgs;
return cp.spawn(hugoBin, args, { stdio: "inherit" }).on("close", code => {
if (code === 0) {
browserSync.reload();
cb();
} else {
browserSync.notify("Hugo build failed :(");
cb("Hugo build failed");
}
});
}

gulp.task("hugo", ["copy"], cb => buildSite(cb));
gulp.task("hugo-preview", ["copy"], cb =>
buildSite(cb, ["--buildDrafts", "--buildFuture"])
);

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

gulp.task("css", () => (
gulp.src("./src/css/**/*.css")
.pipe(postcss([
cssImport({from: "./src/css/main.css"}),
neatgrid(),
nestedcss(),
colorfunctions(),
hdBackgrounds(),
cssextend(),
cssvars({variables: styleVariables})]))
gulp.task("css", () =>
gulp
.src("./src/css/**/*.css")
.pipe(
postcss([
cssImport({ from: "./src/css/main.css" }),
neatgrid(),
nestedcss(),
colorfunctions(),
hdBackgrounds(),
cssextend(),
cssvars({ variables: styleVariables })
])
)
.pipe(gulp.dest("./dist/css"))
.pipe(browserSync.stream())
));
);

gulp.task("js", (cb) => {
gulp.task("js", cb => {
const myConfig = Object.assign({}, webpackConfig);

webpack(myConfig, (err, stats) => {
if (err) throw new gutil.PluginError("webpack", err);
gutil.log("[webpack]", stats.toString({
colors: true,
progress: true
}));
gutil.log(
"[webpack]",
stats.toString({
colors: true,
progress: true
})
);
browserSync.reload();
cb();
});
});

gulp.task("fonts", () => (
gulp.src("./src/fonts/**/*")
gulp.task("fonts", () =>
gulp
.src("./src/fonts/**/*")
.pipe(gulp.dest("./dist/fonts"))
.pipe(browserSync.stream())
));
);

gulp.task("images", () => (
gulp.src("./src/img/**/*")
gulp.task("images", () =>
gulp
.src("./src/img/**/*")
.pipe(gulp.dest("./dist/img"))
.pipe(browserSync.stream())
));
);

gulp.task("copy", () =>
gulp
.src("../.all-contributorsrc")
.pipe(
transform(
"utf8",
content =>
new Promise((resolve, reject) => {
const contributors = JSON.parse(content);
resolve(yaml.dump({ contributors: contributors.contributors }));
})
)
)
.pipe(rename("contributors.yml"))
.pipe(gulp.dest("./site/data"))
);

gulp.task("server", ["hugo", "css", "js", "fonts", "images"], () => {
gulp.task("server", ["css", "js", "fonts", "images", "hugo"], () => {
browserSync.init({
server: {
baseDir: "./dist"
Expand All @@ -77,18 +121,3 @@ gulp.task("server", ["hugo", "css", "js", "fonts", "images"], () => {
gulp.watch("./src/fonts/**/*", ["fonts"]);
gulp.watch("./site/**/*", ["hugo"]);
});

function buildSite(cb, options) {
const args = options ? defaultArgs.concat(options) : defaultArgs;

return cp.spawn(hugoBin, args, {stdio: "inherit"}).on("close", (code) => {
if (code === 0) {
browserSync.reload();
cb();
} else {
browserSync.notify("Hugo build failed :(");
cb("Hugo build failed");
}
});
}

2 changes: 2 additions & 0 deletions website/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
"gulp": "^3.9.1",
"gulp-babel": "^6.1.2",
"gulp-postcss": "^6.1.1",
"gulp-rename": "^1.2.2",
"gulp-transform": "^3.0.5",
"gulp-util": "^3.0.7",
"hugo-bin": "^0.18.0",
"imports-loader": "^0.6.5",
Expand Down
Loading

0 comments on commit b4ad94e

Please sign in to comment.