diff options
author | silverwind <me@silverwind.io> | 2020-08-06 09:04:51 +0200 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-08-06 08:04:51 +0100 |
commit | f1a42f5d5ee0279ddec7973a1ba9236c70bd5b5e (patch) | |
tree | 57cedefa5427775dc2c4b2bf55a711170b344c95 /build | |
parent | 983cbb2c9f5bcdd631ae4744e5b2a6793f0d6dcb (diff) | |
download | gitea-f1a42f5d5ee0279ddec7973a1ba9236c70bd5b5e.tar.gz gitea-f1a42f5d5ee0279ddec7973a1ba9236c70bd5b5e.zip |
Add SVG favicon (#12437)
Co-authored-by: Lunny Xiao <xiaolunwen@gmail.com>
Diffstat (limited to 'build')
-rwxr-xr-x | build/generate-images.js | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/build/generate-images.js b/build/generate-images.js index 7a00395a5b..9b7b820172 100755 --- a/build/generate-images.js +++ b/build/generate-images.js @@ -6,6 +6,7 @@ const {fabric} = require('fabric'); const {DOMParser, XMLSerializer} = require('xmldom'); const {readFile, writeFile} = require('fs').promises; const {resolve} = require('path'); +const Svgo = require('svgo'); function exit(err) { if (err) console.error(err); @@ -20,6 +21,25 @@ function loadSvg(svg) { }); } +async function generateSvgFavicon(svg, outputFile) { + const svgo = new Svgo({ + plugins: [ + {removeDimensions: true}, + { + addAttributesToSVGElement: { + attributes: [ + {'width': '32'}, + {'height': '32'}, + ], + }, + }, + ], + }); + + const {data} = await svgo.optimize(svg); + await writeFile(outputFile, data); +} + async function generate(svg, outputFile, {size, bg, removeDetail} = {}) { const parser = new DOMParser(); const serializer = new XMLSerializer(); @@ -67,6 +87,7 @@ async function generate(svg, outputFile, {size, bg, removeDetail} = {}) { async function main() { const svg = await readFile(resolve(__dirname, '../assets/logo.svg'), 'utf8'); + await generateSvgFavicon(svg, resolve(__dirname, '../public/img/favicon.svg')); await generate(svg, resolve(__dirname, '../public/img/gitea-lg.png'), {size: 880}); await generate(svg, resolve(__dirname, '../public/img/gitea-512.png'), {size: 512}); await generate(svg, resolve(__dirname, '../public/img/gitea-192.png'), {size: 192}); |