1
0
mirror of https://github.com/konpa/devicon.git synced 2025-08-06 14:46:46 +02:00

Optimized SVG using SVGO (#597)

* Added script to optimize svgs

* Updated the svgs using svgo

* Made the optimize svg script into a workflow

* Added npm install step

* Change the env variable bug

* Clean up and updated check svg

* Change label name
This commit is contained in:
Thomas Bui
2021-05-15 12:14:13 -07:00
committed by GitHub
parent 2c6a21d9f4
commit d98a72cb9a
534 changed files with 1432 additions and 10831 deletions

View File

@@ -1,6 +1,8 @@
var gulp = require('gulp');
const svgmin = require("gulp-svgmin")
const sass = require('gulp-sass');
sass.compiler = require('sass')
const yargs = require("yargs")
const fsPromise = require('fs').promises;
const path = require("path");
@@ -149,5 +151,70 @@ function cleanUp() {
}
//////// Update SVG Task ////////
/**
* Update the svg by optimizing it
* and prefixing its ids so it's unique across the repo.
*
* This requires a json list of svg file names to update.
* This must be passed through the commandline arguments.
*/
function optimizeSvg() {
let svgPaths = getAddedModifiedSvg(yargs.argv.filesAddedJson,
yargs.argv.filesModifiedJson)
return gulp.src(svgPaths)
.pipe(svgmin(configOptionCallback))
.pipe(gulp.dest(file => {
return file.base
}))
}
/**
* Get the svgs added and modified from the '/icons' folder only.
* @param {*} filesAddedJson - the files that were added in this commit.
* @param {*} filesModifiedJson - the files that were modified in this commit.
* @returns a list of the svg file paths that were added/modified in this pr as Path.
* It will only return icons in '/icons' path (see https://github.com/devicons/devicon/issues/505)
*/
function getAddedModifiedSvg(filesAddedJson, filesModifiedJson) {
const filesAdded = JSON.parse(filesAddedJson),
filesModified = JSON.parse(filesModifiedJson)
files = filesAdded.concat(filesModified)
return files.filter(filename => {
if (path.extname(filename) == ".svg"
&& path.dirname(filename).includes('icons/'))
return filename
})
}
/**
* Create a config option for each file.
* @param {Object} file - Gulp Vinyl instance of the file
* being processed.
* @returns a SVGO config object.
*/
function configOptionCallback(file) {
return {
plugins: [
{
prefixIds: {
prefix: file.stem, // add file name to ids
delim: "-"
}
},
{
removeViewBox: false // keep viewbox
},
{
removeDimensions: true // remove height and width
}
]
}
}
exports.updateCss = createDeviconMinCSS;
exports.clean = cleanUp;
exports.optimizeSvg = optimizeSvg;