mirror of
https://github.com/searxng/searxng
synced 2024-01-01 19:24:07 +01:00
WIP: remove grunt-image
This commit is contained in:
parent
18d895ffed
commit
58a2352537
4 changed files with 39 additions and 45 deletions
|
@ -3,6 +3,7 @@
|
||||||
module.exports = function (grunt) {
|
module.exports = function (grunt) {
|
||||||
|
|
||||||
const eachAsync = require('each-async');
|
const eachAsync = require('each-async');
|
||||||
|
const svgo = require('svgo');
|
||||||
|
|
||||||
function file_exists (filepath) {
|
function file_exists (filepath) {
|
||||||
// filter function to exit grunt task with error if a (src) file not exists
|
// filter function to exit grunt task with error if a (src) file not exists
|
||||||
|
@ -27,7 +28,7 @@ module.exports = function (grunt) {
|
||||||
'copy',
|
'copy',
|
||||||
'uglify',
|
'uglify',
|
||||||
'less',
|
'less',
|
||||||
'image',
|
'optimizesvg',
|
||||||
'svg2png',
|
'svg2png',
|
||||||
'svg2jinja'
|
'svg2jinja'
|
||||||
]
|
]
|
||||||
|
@ -139,10 +140,19 @@ module.exports = function (grunt) {
|
||||||
],
|
],
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
image: {
|
optimizesvg: {
|
||||||
svg4web: {
|
svg4web: {
|
||||||
options: {
|
config: {
|
||||||
svgo: ['--config', 'svg4web.svgo.js']
|
plugins: [
|
||||||
|
{
|
||||||
|
name: 'preset-default',
|
||||||
|
},
|
||||||
|
// make diff friendly
|
||||||
|
'sortAttrs',
|
||||||
|
// Optimize SVG for WEB usage
|
||||||
|
'convertStyleToAttrs',
|
||||||
|
'removeXMLNS'
|
||||||
|
],
|
||||||
},
|
},
|
||||||
files: {
|
files: {
|
||||||
'<%= _templates %>/simple/searxng-wordmark.min.svg': '<%= _brand %>/searxng-wordmark.svg',
|
'<%= _templates %>/simple/searxng-wordmark.min.svg': '<%= _brand %>/searxng-wordmark.svg',
|
||||||
|
@ -151,8 +161,14 @@ module.exports = function (grunt) {
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
favicon: {
|
favicon: {
|
||||||
options: {
|
config: {
|
||||||
svgo: ['--config', 'svg4favicon.svgo.js']
|
plugins: [
|
||||||
|
{
|
||||||
|
name: 'preset-default',
|
||||||
|
},
|
||||||
|
// make diff friendly
|
||||||
|
'sortAttrs',
|
||||||
|
],
|
||||||
},
|
},
|
||||||
files: {
|
files: {
|
||||||
'img/favicon.svg': '<%= _brand %>/searxng-wordmark.svg'
|
'img/favicon.svg': '<%= _brand %>/searxng-wordmark.svg'
|
||||||
|
@ -197,8 +213,21 @@ module.exports = function (grunt) {
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
grunt.registerMultiTask('optimizesvg', 'Optimize SVG', function () {
|
||||||
|
for (const file of this.files) {
|
||||||
|
try {
|
||||||
|
const svgContent = grunt.file.read(file.src[0], { encoding: 'utf8' });
|
||||||
|
const optimizedSvgContent = svgo.optimize(svgContent, this.config);
|
||||||
|
grunt.file.write(file.dest, optimizedSvgContent.data, { encoding: 'utf8' });
|
||||||
|
grunt.log.ok(file.dest + ' created (' + optimizedSvgContent.data.length + ' bytes)');
|
||||||
|
} catch (err) {
|
||||||
|
grunt.log.error(err);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
grunt.registerMultiTask('svg2jinja', 'Create Jinja2 macro', function () {
|
grunt.registerMultiTask('svg2jinja', 'Create Jinja2 macro', function () {
|
||||||
const ejs = require('ejs'), svgo = require('svgo');
|
const ejs = require('ejs');
|
||||||
const icons = {}
|
const icons = {}
|
||||||
for (const iconName in this.data.src) {
|
for (const iconName in this.data.src) {
|
||||||
const svgFileName = this.data.src[iconName];
|
const svgFileName = this.data.src[iconName];
|
||||||
|
@ -286,7 +315,6 @@ module.exports = function (grunt) {
|
||||||
grunt.loadNpmTasks('grunt-contrib-watch');
|
grunt.loadNpmTasks('grunt-contrib-watch');
|
||||||
grunt.loadNpmTasks('grunt-contrib-copy');
|
grunt.loadNpmTasks('grunt-contrib-copy');
|
||||||
grunt.loadNpmTasks('grunt-contrib-uglify');
|
grunt.loadNpmTasks('grunt-contrib-uglify');
|
||||||
grunt.loadNpmTasks('grunt-image');
|
|
||||||
grunt.loadNpmTasks('grunt-contrib-less');
|
grunt.loadNpmTasks('grunt-contrib-less');
|
||||||
grunt.loadNpmTasks('grunt-contrib-cssmin');
|
grunt.loadNpmTasks('grunt-contrib-cssmin');
|
||||||
grunt.loadNpmTasks('grunt-stylelint');
|
grunt.loadNpmTasks('grunt-stylelint');
|
||||||
|
@ -300,7 +328,7 @@ module.exports = function (grunt) {
|
||||||
'copy',
|
'copy',
|
||||||
'uglify',
|
'uglify',
|
||||||
'less',
|
'less',
|
||||||
'image',
|
'optimizesvg',
|
||||||
'svg2png',
|
'svg2png',
|
||||||
'svg2jinja',
|
'svg2jinja',
|
||||||
]);
|
]);
|
||||||
|
|
|
@ -18,7 +18,8 @@
|
||||||
"stylelint": "^13.13.1",
|
"stylelint": "^13.13.1",
|
||||||
"stylelint-config-standard": "^22.0.0",
|
"stylelint-config-standard": "^22.0.0",
|
||||||
"ejs": "^3.1.8",
|
"ejs": "^3.1.8",
|
||||||
"svgo": "^3.0.0"
|
"svgo": "^3.0.0",
|
||||||
|
"each-async": "2.0.0"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"autocomplete-js": "2.7.1",
|
"autocomplete-js": "2.7.1",
|
||||||
|
|
|
@ -1,16 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*
|
|
||||||
* svgo config: Optimize SVG for WEB usage
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
plugins: [
|
|
||||||
{
|
|
||||||
name: 'preset-default',
|
|
||||||
},
|
|
||||||
// make diff friendly
|
|
||||||
'sortAttrs',
|
|
||||||
],
|
|
||||||
};
|
|
|
@ -1,19 +0,0 @@
|
||||||
/**
|
|
||||||
* @license
|
|
||||||
* SPDX-License-Identifier: AGPL-3.0-or-later
|
|
||||||
*
|
|
||||||
* svgo config: Optimize SVG for WEB usage
|
|
||||||
*/
|
|
||||||
|
|
||||||
module.exports = {
|
|
||||||
plugins: [
|
|
||||||
{
|
|
||||||
name: 'preset-default',
|
|
||||||
},
|
|
||||||
// make diff friendly
|
|
||||||
'sortAttrs',
|
|
||||||
// Optimize SVG for WEB usage
|
|
||||||
'convertStyleToAttrs',
|
|
||||||
'removeXMLNS'
|
|
||||||
],
|
|
||||||
};
|
|
Loading…
Add table
Reference in a new issue