diff --git a/searx/static/themes/simple/gruntfile.js b/searx/static/themes/simple/gruntfile.js index 630cac212..e3dc5f865 100644 --- a/searx/static/themes/simple/gruntfile.js +++ b/searx/static/themes/simple/gruntfile.js @@ -3,6 +3,7 @@ module.exports = function (grunt) { const eachAsync = require('each-async'); + const svgo = require('svgo'); function file_exists (filepath) { // filter function to exit grunt task with error if a (src) file not exists @@ -27,7 +28,7 @@ module.exports = function (grunt) { 'copy', 'uglify', 'less', - 'image', + 'optimizesvg', 'svg2png', 'svg2jinja' ] @@ -139,10 +140,19 @@ module.exports = function (grunt) { ], }, }, - image: { + optimizesvg: { svg4web: { - options: { - svgo: ['--config', 'svg4web.svgo.js'] + config: { + plugins: [ + { + name: 'preset-default', + }, + // make diff friendly + 'sortAttrs', + // Optimize SVG for WEB usage + 'convertStyleToAttrs', + 'removeXMLNS' + ], }, files: { '<%= _templates %>/simple/searxng-wordmark.min.svg': '<%= _brand %>/searxng-wordmark.svg', @@ -151,8 +161,14 @@ module.exports = function (grunt) { } }, favicon: { - options: { - svgo: ['--config', 'svg4favicon.svgo.js'] + config: { + plugins: [ + { + name: 'preset-default', + }, + // make diff friendly + 'sortAttrs', + ], }, files: { '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 () { - const ejs = require('ejs'), svgo = require('svgo'); + const ejs = require('ejs'); const icons = {} for (const iconName in this.data.src) { const svgFileName = this.data.src[iconName]; @@ -286,7 +315,6 @@ module.exports = function (grunt) { grunt.loadNpmTasks('grunt-contrib-watch'); grunt.loadNpmTasks('grunt-contrib-copy'); grunt.loadNpmTasks('grunt-contrib-uglify'); - grunt.loadNpmTasks('grunt-image'); grunt.loadNpmTasks('grunt-contrib-less'); grunt.loadNpmTasks('grunt-contrib-cssmin'); grunt.loadNpmTasks('grunt-stylelint'); @@ -300,7 +328,7 @@ module.exports = function (grunt) { 'copy', 'uglify', 'less', - 'image', + 'optimizesvg', 'svg2png', 'svg2jinja', ]); diff --git a/searx/static/themes/simple/package.json b/searx/static/themes/simple/package.json index 91ceb3f22..30c8409ec 100644 --- a/searx/static/themes/simple/package.json +++ b/searx/static/themes/simple/package.json @@ -18,7 +18,8 @@ "stylelint": "^13.13.1", "stylelint-config-standard": "^22.0.0", "ejs": "^3.1.8", - "svgo": "^3.0.0" + "svgo": "^3.0.0", + "each-async": "2.0.0" }, "dependencies": { "autocomplete-js": "2.7.1", diff --git a/searx/static/themes/simple/svg4favicon.svgo.js b/searx/static/themes/simple/svg4favicon.svgo.js deleted file mode 100644 index b9dd0da8e..000000000 --- a/searx/static/themes/simple/svg4favicon.svgo.js +++ /dev/null @@ -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', - ], -}; diff --git a/searx/static/themes/simple/svg4web.svgo.js b/searx/static/themes/simple/svg4web.svgo.js deleted file mode 100644 index 83f74cde1..000000000 --- a/searx/static/themes/simple/svg4web.svgo.js +++ /dev/null @@ -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' - ], -};