mirror of
				https://github.com/searxng/searxng
				synced 2024-01-01 19:24:07 +01:00 
			
		
		
		
	Merge pull request #541 from dalf/simple-theme-svg2png
Simple theme svg2png
This commit is contained in:
		
						commit
						d0e21a01b4
					
				
					 4 changed files with 70 additions and 48 deletions
				
			
		
							
								
								
									
										30
									
								
								manage
									
										
									
									
									
								
							
							
						
						
									
										30
									
								
								manage
									
										
									
									
									
								
							|  | @ -708,42 +708,12 @@ themes.oscar() { | ||||||
| themes.simple() { | themes.simple() { | ||||||
|     local static="searx/static/themes/simple" |     local static="searx/static/themes/simple" | ||||||
|     (   set -e |     (   set -e | ||||||
|         convert_if_newer "src/brand/searxng-wordmark.svg" "$static/img/favicon.png" \ |  | ||||||
|                          -transparent white -resize 64x64 |  | ||||||
|         build_msg GRUNT "theme: simple" |         build_msg GRUNT "theme: simple" | ||||||
|         npm --prefix searx/static/themes/simple run build |         npm --prefix searx/static/themes/simple run build | ||||||
|     ) |     ) | ||||||
|     dump_return $? |     dump_return $? | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| convert_if_newer() { |  | ||||||
| 
 |  | ||||||
|     # usage: convert_if_newer <origfile> <outfile> [<options>, ...] |  | ||||||
|     # |  | ||||||
|     #    convert_if_newer "path/to/origin.svg" "path/to/converted.png" -resize 100x100 |  | ||||||
|     # |  | ||||||
|     # Run's ImageMagik' convert comand to generate <outfile> from <origfile>, if |  | ||||||
|     # <origfile> is newer than <outfile>.  The command line is to convert is:: |  | ||||||
|     # |  | ||||||
|     #    convert <origfile> [<options>, ...] <outfile> |  | ||||||
| 
 |  | ||||||
|     local src_file="$1" && shift |  | ||||||
|     local dst_file="$1" && shift |  | ||||||
| 
 |  | ||||||
|     if [[ "${src_file}" -nt "${dst_file}" ]]; then |  | ||||||
|         if ! required_commands convert; then |  | ||||||
|             info_msg "to install build tools use::" |  | ||||||
|             info_msg "   sudo -H ./utils/searx.sh install buildhost" |  | ||||||
|             die 1 "install needed build tools first" |  | ||||||
|         fi |  | ||||||
|         build_msg CONVERT "${src_file}" "$@" "${dst_file}" |  | ||||||
|         convert "${src_file}" "$@" "${dst_file}" |  | ||||||
|     else |  | ||||||
|         build_msg CONVERT "${dst_file} (up-to-date)" |  | ||||||
|     fi |  | ||||||
| } |  | ||||||
| 
 |  | ||||||
| 
 |  | ||||||
| PYLINT_FILES=() | PYLINT_FILES=() | ||||||
| while IFS= read -r line; do | while IFS= read -r line; do | ||||||
|    PYLINT_FILES+=("$line") |    PYLINT_FILES+=("$line") | ||||||
|  |  | ||||||
|  | @ -2,7 +2,7 @@ | ||||||
| 
 | 
 | ||||||
| module.exports = function(grunt) { | module.exports = function(grunt) { | ||||||
| 
 | 
 | ||||||
|   const path = require('path'); |   const eachAsync = require('each-async'); | ||||||
| 
 | 
 | ||||||
|   grunt.initConfig({ |   grunt.initConfig({ | ||||||
| 
 | 
 | ||||||
|  | @ -13,7 +13,17 @@ module.exports = function(grunt) { | ||||||
|     watch: { |     watch: { | ||||||
|       scripts: { |       scripts: { | ||||||
|         files: ['gruntfile.js', 'src/**'], |         files: ['gruntfile.js', 'src/**'], | ||||||
|         tasks: ['eslint', 'copy', 'concat', 'svg2jinja', 'uglify', 'image', 'less:development', 'less:production'] |         tasks: [ | ||||||
|  |           'eslint', | ||||||
|  |           'copy', | ||||||
|  |           'concat', | ||||||
|  |           'uglify', | ||||||
|  |           'less:development', | ||||||
|  |           'less:production', | ||||||
|  |           'image', | ||||||
|  |           'svg2png', | ||||||
|  |           'svg2jinja' | ||||||
|  |         ] | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     eslint: { |     eslint: { | ||||||
|  | @ -78,14 +88,18 @@ module.exports = function(grunt) { | ||||||
|         }, |         }, | ||||||
|         files: { |         files: { | ||||||
|           'js/searxng.head.js': ['src/js/head/*.js'], |           'js/searxng.head.js': ['src/js/head/*.js'], | ||||||
|           'js/searxng.js': ['src/js/main/*.js', '../__common__/js/*.js', './node_modules/autocomplete-js/dist/autocomplete.js'] |           'js/searxng.js': [ | ||||||
|  |             'src/js/main/*.js', | ||||||
|  |             '../__common__/js/*.js', | ||||||
|  |             './node_modules/autocomplete-js/dist/autocomplete.js' | ||||||
|  |           ] | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     uglify: { |     uglify: { | ||||||
|       options: { |       options: { | ||||||
|         output: { |         output: { | ||||||
| 	        comments: 'some' |           comments: 'some' | ||||||
|         }, |         }, | ||||||
|         ie8: false, |         ie8: false, | ||||||
|         warnings: true, |         warnings: true, | ||||||
|  | @ -100,16 +114,6 @@ module.exports = function(grunt) { | ||||||
|         } |         } | ||||||
|       } |       } | ||||||
|     }, |     }, | ||||||
|     image: { |  | ||||||
|       svg4web: { |  | ||||||
|         options: { |  | ||||||
|           svgo: ['--config', 'svg4web.svgo.js'] |  | ||||||
|         }, |  | ||||||
|         files: { |  | ||||||
|           '<%= _templates %>/__common__/searxng-wordmark.min.svg': '<%= _brand %>/searxng-wordmark.svg' |  | ||||||
|         } |  | ||||||
|       } |  | ||||||
|     }, |  | ||||||
|     less: { |     less: { | ||||||
|       development: { |       development: { | ||||||
|         options: { |         options: { | ||||||
|  | @ -137,6 +141,23 @@ module.exports = function(grunt) { | ||||||
|         } |         } | ||||||
|       }, |       }, | ||||||
|     }, |     }, | ||||||
|  |     image: { | ||||||
|  |       svg4web: { | ||||||
|  |         options: { | ||||||
|  |           svgo: ['--config', 'svg4web.svgo.js'] | ||||||
|  |         }, | ||||||
|  |         files: { | ||||||
|  |           '<%= _templates %>/__common__/searxng-wordmark.min.svg': '<%= _brand %>/searxng-wordmark.svg' | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|  |     svg2png: { | ||||||
|  |       favicon: { | ||||||
|  |         files: { | ||||||
|  |           'img/favicon.png': '<%= _brand %>/searxng-wordmark.svg' | ||||||
|  |         } | ||||||
|  |       } | ||||||
|  |     }, | ||||||
|     svg2jinja: { |     svg2jinja: { | ||||||
|       all: { |       all: { | ||||||
|         src: { |         src: { | ||||||
|  | @ -165,7 +186,6 @@ module.exports = function(grunt) { | ||||||
|     }, |     }, | ||||||
|   }); |   }); | ||||||
| 
 | 
 | ||||||
| 
 |  | ||||||
|   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'), svgo = require('svgo'); | ||||||
|     const icons = {} |     const icons = {} | ||||||
|  | @ -222,6 +242,36 @@ module.exports = function(grunt) { | ||||||
|     grunt.log.ok(this.data.dest + " created"); |     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-watch'); | ||||||
|   grunt.loadNpmTasks('grunt-contrib-copy'); |   grunt.loadNpmTasks('grunt-contrib-copy'); | ||||||
|   grunt.loadNpmTasks('grunt-contrib-uglify'); |   grunt.loadNpmTasks('grunt-contrib-uglify'); | ||||||
|  | @ -240,10 +290,11 @@ module.exports = function(grunt) { | ||||||
|     'stylelint', |     'stylelint', | ||||||
|     'copy', |     'copy', | ||||||
|     'concat', |     'concat', | ||||||
|     'svg2jinja', |  | ||||||
|     'uglify', |     'uglify', | ||||||
|     'image', |  | ||||||
|     'less:development', |     'less:development', | ||||||
|     'less:production' |     'less:production', | ||||||
|  |     'image', | ||||||
|  |     'svg2png', | ||||||
|  |     'svg2jinja', | ||||||
|   ]); |   ]); | ||||||
| }; | }; | ||||||
|  |  | ||||||
										
											Binary file not shown.
										
									
								
							| Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 5 KiB | 
|  | @ -16,6 +16,7 @@ | ||||||
|     "ionicons": "^6.0.0", |     "ionicons": "^6.0.0", | ||||||
|     "less": "^4.1.1", |     "less": "^4.1.1", | ||||||
|     "less-plugin-clean-css": "^1.5.1", |     "less-plugin-clean-css": "^1.5.1", | ||||||
|  |     "sharp": "^0.29.3", | ||||||
|     "stylelint": "^13.13.1", |     "stylelint": "^13.13.1", | ||||||
|     "stylelint-config-standard": "^22.0.0", |     "stylelint-config-standard": "^22.0.0", | ||||||
|     "ejs": "^3.1.6", |     "ejs": "^3.1.6", | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Markus Heiser
						Markus Heiser