summaryrefslogtreecommitdiff
path: root/searx/static/themes/simple/gruntfile.js
diff options
context:
space:
mode:
authorAlexandre Flament <alex@al-f.net>2021-11-23 20:18:09 +0100
committerMarkus Heiser <markus.heiser@darmarit.de>2021-11-28 20:05:37 +0100
commit59f4c792b498ef399dad5643576327da8ed122f2 (patch)
tree315bd7aa599b5b5543f0fed7f98bbebac9b6d0c0 /searx/static/themes/simple/gruntfile.js
parent8c4c4259d4f9a856c8c7773591b40be9aef97bb1 (diff)
downloadsearxng-59f4c792b498ef399dad5643576327da8ed122f2.tar.gz
searxng-59f4c792b498ef399dad5643576327da8ed122f2.zip
[mod] simple theme: use sharp instead of convert to create .png from .svg
define a custom grunt task, since grunt-sharp is too old (it can't be installed). in gruntfile.js, the image tasks are moved at the end the build chain. Signed-off-by: Markus Heiser <markus.heiser@darmarit.de>
Diffstat (limited to 'searx/static/themes/simple/gruntfile.js')
-rw-r--r--searx/static/themes/simple/gruntfile.js41
1 files changed, 41 insertions, 0 deletions
diff --git a/searx/static/themes/simple/gruntfile.js b/searx/static/themes/simple/gruntfile.js
index 83989397d..d51316dcf 100644
--- a/searx/static/themes/simple/gruntfile.js
+++ b/searx/static/themes/simple/gruntfile.js
@@ -2,6 +2,8 @@
module.exports = function(grunt) {
+ const eachAsync = require('each-async');
+
grunt.initConfig({
_brand: '../../../../src/brand',
@@ -19,6 +21,7 @@ module.exports = function(grunt) {
'less:development',
'less:production',
'image',
+ 'svg2png',
'svg2jinja'
]
}
@@ -148,6 +151,13 @@ module.exports = function(grunt) {
}
}
},
+ svg2png: {
+ favicon: {
+ files: {
+ 'img/favicon.png': '<%= _brand %>/searxng-wordmark.svg'
+ }
+ }
+ },
svg2jinja: {
all: {
src: {
@@ -232,6 +242,36 @@ module.exports = function(grunt) {
grunt.log.ok(this.data.dest + " created");
});
+ grunt.registerMultiTask('svg2png', 'Convert SVG to PNG', function () {
+ const sharp = require('sharp'), done = this.async();
+ eachAsync(this.files, async (file, _index, next) => {
+ try {
+ if (file.src.length != 1) {
+ next("this task supports only one source per destination");
+ }
+ const info = await sharp(file.src[0])
+ .png({
+ force: true,
+ compressionLevel: 9,
+ palette: true,
+ })
+ .toFile(file.dest);
+ grunt.log.ok(file.dest + ' created (' + info.size + ' bytes, ' + info.width + 'px * ' + info.height + 'px)');
+ next();
+ } catch (error) {
+ grunt.fatal(error);
+ next(error);
+ }
+ }, error => {
+ if (error) {
+ grunt.fatal(error);
+ done(error);
+ } else {
+ done();
+ }
+ });
+ });
+
grunt.loadNpmTasks('grunt-contrib-watch');
grunt.loadNpmTasks('grunt-contrib-copy');
grunt.loadNpmTasks('grunt-contrib-uglify');
@@ -254,6 +294,7 @@ module.exports = function(grunt) {
'less:development',
'less:production',
'image',
+ 'svg2png',
'svg2jinja',
]);
};