2020-09-10 20:23:24 +00:00
|
|
|
const gulp = require("gulp");
|
|
|
|
const rename = require("gulp-rename");
|
|
|
|
const sass = require("gulp-sass");
|
|
|
|
const cleanCSS = require("gulp-clean-css");
|
|
|
|
const autoprefixer = require("gulp-autoprefixer");
|
|
|
|
const iconfont = require("gulp-iconfont");
|
2020-11-22 18:06:04 +00:00
|
|
|
const clean = require("gulp-clean");
|
2020-01-12 14:33:02 +00:00
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
const realFavicon = require("gulp-real-favicon");
|
|
|
|
const path = require("path");
|
|
|
|
const fs = require("fs");
|
2020-01-12 14:33:02 +00:00
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
const svgSprite = require("gulp-svg-sprite");
|
2020-11-22 18:06:04 +00:00
|
|
|
const rev = require("gulp-rev");
|
2020-01-12 14:33:02 +00:00
|
|
|
|
2020-11-22 18:06:04 +00:00
|
|
|
var CSSDEST = "assets/";
|
|
|
|
var FAVICON_DATA_FILE = "build/faviconData.json";
|
2020-03-15 15:37:48 +00:00
|
|
|
var TIMESTAMP = Math.round(Date.now() / 1000);
|
2020-01-12 14:33:02 +00:00
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
gulp.task("sass", function () {
|
|
|
|
return gulp
|
2020-11-09 21:06:06 +00:00
|
|
|
.src("src/sass/{main,print,mobile}.scss")
|
2020-09-10 20:23:24 +00:00
|
|
|
.pipe(sass({ errLogToConsole: true }))
|
|
|
|
.pipe(cleanCSS({ format: "beautify" }))
|
|
|
|
.pipe(
|
|
|
|
autoprefixer({
|
|
|
|
cascade: false,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.pipe(gulp.dest(CSSDEST))
|
|
|
|
.pipe(cleanCSS())
|
|
|
|
.pipe(rename({ extname: ".min.css" }))
|
|
|
|
.pipe(gulp.dest(CSSDEST));
|
2020-01-12 14:33:02 +00:00
|
|
|
});
|
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
gulp.task("favicon-generate", function (done) {
|
|
|
|
realFavicon.generateFavicon(
|
|
|
|
{
|
|
|
|
masterPicture: "src/favicon/favicon-master.svg",
|
|
|
|
dest: "static/favicon",
|
2020-11-09 21:06:06 +00:00
|
|
|
iconsPath: "/favicon",
|
2020-09-10 20:23:24 +00:00
|
|
|
design: {
|
|
|
|
ios: {
|
|
|
|
pictureAspect: "backgroundAndMargin",
|
2020-11-09 21:06:06 +00:00
|
|
|
backgroundColor: "#2f333e",
|
2020-09-10 20:23:24 +00:00
|
|
|
margin: "14%",
|
|
|
|
assets: {
|
|
|
|
ios6AndPriorIcons: false,
|
|
|
|
ios7AndLaterIcons: false,
|
|
|
|
precomposedIcons: false,
|
|
|
|
declareOnlyDefaultIcon: true,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
desktopBrowser: {},
|
|
|
|
windows: {
|
|
|
|
pictureAspect: "whiteSilhouette",
|
2020-11-09 21:06:06 +00:00
|
|
|
backgroundColor: "#2f333e",
|
2020-09-10 20:23:24 +00:00
|
|
|
onConflict: "override",
|
|
|
|
assets: {
|
|
|
|
windows80Ie10Tile: false,
|
|
|
|
windows10Ie11EdgeTiles: {
|
|
|
|
small: false,
|
|
|
|
medium: true,
|
|
|
|
big: false,
|
|
|
|
rectangle: false,
|
2020-03-15 15:37:48 +00:00
|
|
|
},
|
2020-09-10 20:23:24 +00:00
|
|
|
},
|
2020-03-15 15:37:48 +00:00
|
|
|
},
|
2020-09-10 20:23:24 +00:00
|
|
|
androidChrome: {
|
|
|
|
pictureAspect: "shadow",
|
2020-11-09 21:06:06 +00:00
|
|
|
themeColor: "#2f333e",
|
2020-09-10 20:23:24 +00:00
|
|
|
manifest: {
|
|
|
|
display: "standalone",
|
|
|
|
orientation: "notSet",
|
|
|
|
onConflict: "override",
|
|
|
|
declared: true,
|
|
|
|
},
|
|
|
|
assets: {
|
|
|
|
legacyIcon: false,
|
|
|
|
lowResolutionIcons: false,
|
|
|
|
},
|
2020-03-15 15:37:48 +00:00
|
|
|
},
|
2020-09-10 20:23:24 +00:00
|
|
|
safariPinnedTab: {
|
2020-11-09 21:06:06 +00:00
|
|
|
pictureAspect: "silhouette",
|
|
|
|
themeColor: "#2f333e",
|
2020-09-10 20:23:24 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
settings: {
|
|
|
|
scalingAlgorithm: "Mitchell",
|
|
|
|
errorOnImageTooSmall: false,
|
|
|
|
readmeFile: false,
|
|
|
|
htmlCodeFile: false,
|
|
|
|
usePathAsIs: false,
|
|
|
|
},
|
|
|
|
markupFile: FAVICON_DATA_FILE,
|
|
|
|
},
|
|
|
|
function () {
|
|
|
|
done();
|
|
|
|
}
|
|
|
|
);
|
2020-01-12 14:33:02 +00:00
|
|
|
});
|
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
gulp.task("favicon-check-update", function (done) {
|
|
|
|
var currentVersion = JSON.parse(fs.readFileSync(FAVICON_DATA_FILE)).version;
|
|
|
|
realFavicon.checkForUpdates(currentVersion, function (err) {
|
|
|
|
if (err) {
|
|
|
|
throw err;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
done();
|
2020-01-12 14:33:02 +00:00
|
|
|
});
|
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
gulp.task("svg-sprite", function () {
|
|
|
|
config = {
|
2020-11-09 21:06:06 +00:00
|
|
|
shape: {
|
|
|
|
dimension: {
|
|
|
|
maxWidth: 24,
|
|
|
|
maxHeight: 24,
|
|
|
|
attributes: false,
|
|
|
|
},
|
|
|
|
spacing: {
|
2020-11-16 21:24:23 +00:00
|
|
|
padding: 2,
|
2020-11-09 21:06:06 +00:00
|
|
|
box: "content",
|
|
|
|
},
|
2020-11-22 18:06:04 +00:00
|
|
|
dest: "build/intermediate-svg",
|
2020-11-09 21:06:06 +00:00
|
|
|
},
|
2020-09-10 20:23:24 +00:00
|
|
|
svg: {
|
|
|
|
xmlDeclaration: false,
|
|
|
|
rootAttributes: {
|
|
|
|
style: "position: absolute; width: 0; height: 0; overflow: hidden;",
|
|
|
|
},
|
|
|
|
},
|
|
|
|
mode: {
|
|
|
|
inline: true,
|
|
|
|
symbol: {
|
2020-11-09 21:06:06 +00:00
|
|
|
dest: "layouts/partials/",
|
2020-09-10 20:23:24 +00:00
|
|
|
sprite: "svg-icon-symbols.html",
|
|
|
|
bust: false,
|
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-01-12 14:33:02 +00:00
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
return gulp
|
|
|
|
.src("src/icons/*.svg")
|
|
|
|
.pipe(svgSprite(config))
|
2020-11-09 21:06:06 +00:00
|
|
|
.pipe(gulp.dest("."));
|
2020-03-15 15:37:48 +00:00
|
|
|
});
|
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
gulp.task("iconfont", function () {
|
|
|
|
var lastUnicode = 0xea01;
|
|
|
|
var files = fs.readdirSync("src/iconfont");
|
2020-03-15 17:38:10 +00:00
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
// Filter files with containing unicode value
|
|
|
|
// and set last unicode
|
|
|
|
files.forEach(function (file) {
|
|
|
|
var basename = path.basename(file);
|
|
|
|
var matches = basename.match(/^(?:((?:u[0-9a-f]{4,6},?)+)\-)?(.+)\.svg$/i);
|
|
|
|
var currentCode = -1;
|
2020-03-15 17:38:10 +00:00
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
if (matches && matches[1]) {
|
|
|
|
currentCode = parseInt(matches[1].split("u")[1], 16);
|
|
|
|
}
|
2020-03-15 17:38:10 +00:00
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
if (currentCode >= lastUnicode) {
|
|
|
|
lastUnicode = ++currentCode;
|
|
|
|
}
|
|
|
|
});
|
2020-03-15 17:38:10 +00:00
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
return gulp
|
|
|
|
.src(["src/iconfont/*.svg"])
|
|
|
|
.pipe(
|
|
|
|
iconfont({
|
|
|
|
startUnicode: lastUnicode,
|
2020-11-22 18:06:04 +00:00
|
|
|
fontName: "GeekdocIcons",
|
|
|
|
prependUnicode: true,
|
2020-09-10 20:23:24 +00:00
|
|
|
normalize: true,
|
|
|
|
fontHeight: 1001,
|
|
|
|
centerHorizontally: true,
|
2020-11-22 18:06:04 +00:00
|
|
|
formats: ["woff", "woff2"],
|
|
|
|
timestamp: TIMESTAMP,
|
2020-09-10 20:23:24 +00:00
|
|
|
})
|
|
|
|
)
|
|
|
|
.pipe(gulp.dest("static/fonts/"));
|
2020-01-12 14:33:02 +00:00
|
|
|
});
|
|
|
|
|
2020-11-22 18:06:04 +00:00
|
|
|
gulp.task("asset-rev", function () {
|
|
|
|
return gulp
|
|
|
|
.src(["assets/*.min.css", "assets/js/*.min.js"], {
|
|
|
|
base: "static",
|
|
|
|
})
|
|
|
|
.pipe(gulp.dest("build/assets"))
|
|
|
|
.pipe(rev())
|
|
|
|
.pipe(gulp.dest("static"))
|
|
|
|
.pipe(
|
|
|
|
rev.manifest("data/assets-static.json", {
|
|
|
|
base: "data",
|
|
|
|
merge: true,
|
|
|
|
})
|
|
|
|
)
|
|
|
|
.pipe(rename("assets.json"))
|
|
|
|
.pipe(gulp.dest("data"));
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("asset-rm", function () {
|
|
|
|
return gulp
|
|
|
|
.src(["build/assets", "static/js/*-*.js", "static/*-*.css"], {
|
|
|
|
read: false,
|
|
|
|
allowEmpty: true,
|
|
|
|
})
|
|
|
|
.pipe(clean());
|
|
|
|
});
|
|
|
|
|
|
|
|
gulp.task("asset", gulp.series("asset-rm", "asset-rev"));
|
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
gulp.task(
|
|
|
|
"default",
|
2020-11-22 18:06:04 +00:00
|
|
|
gulp.series("sass", "svg-sprite", "iconfont", "favicon-generate", "asset")
|
2020-09-10 20:23:24 +00:00
|
|
|
);
|
2020-01-12 14:33:02 +00:00
|
|
|
|
2020-09-10 20:23:24 +00:00
|
|
|
gulp.task("devel", function () {
|
2020-11-22 18:06:04 +00:00
|
|
|
gulp.watch("src/sass/**/*.*css", gulp.series("sass", "asset"));
|
2020-01-12 14:33:02 +00:00
|
|
|
});
|