forked from go-gitea/gitea
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Remove external dependencies and replace it with a node script that does does the same. - Move detail removal from gitea-sm.png to favicon.png - Remove favicon.ico and its generation, it is unused and we already serve favicon.png in its place. Fixes: go-gitea#12314
- Loading branch information
1 parent
ea1ed80
commit 9e1edbf
Showing
12 changed files
with
65 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
#!/usr/bin/env node | ||
'use strict'; | ||
|
||
const imageminZopfli = require('imagemin-zopfli'); | ||
const svg2img = require('svg2img'); | ||
const {DOMParser, XMLSerializer} = require('xmldom'); | ||
const {promisify} = require('util'); | ||
const {readFile, writeFile} = require('fs').promises; | ||
const {resolve} = require('path'); | ||
|
||
function exit(err) { | ||
if (err) console.error(err); | ||
process.exit(err ? 1 : 0); | ||
} | ||
|
||
async function generate(svg, outputFile, {size, bg, removeDetail} = {}) { | ||
const parser = new DOMParser(); | ||
const serializer = new XMLSerializer(); | ||
const document = parser.parseFromString(svg); | ||
|
||
if (bg) { | ||
const rect = parser.parseFromString('<rect width="100%" height="100%" fill="white"/>'); | ||
document.documentElement.insertBefore(rect, document.documentElement.firstChild); | ||
} | ||
|
||
if (removeDetail) { | ||
for (const el of Array.from(document.getElementsByTagName('g') || [])) { | ||
for (const attribute of Array.from(el.attributes || [])) { | ||
if (attribute.name === 'class' && attribute.value === 'detail-remove') { | ||
el.parentNode.removeChild(el); | ||
} | ||
} | ||
} | ||
} | ||
|
||
const processedSvg = serializer.serializeToString(document); | ||
const png = await promisify(svg2img)(processedSvg, { | ||
width: size, | ||
height: size, | ||
preserveAspectRatio: 'xMinYMid meet', | ||
}); | ||
|
||
const optimizedPng = await imageminZopfli({more: true})(png); | ||
await writeFile(outputFile, optimizedPng); | ||
} | ||
|
||
async function main() { | ||
const svg = await readFile(resolve(__dirname, '../assets/logo.svg'), 'utf8'); | ||
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}); | ||
await generate(svg, resolve(__dirname, '../public/img/gitea-sm.png'), {size: 120}); | ||
await generate(svg, resolve(__dirname, '../public/img/avatar_default.png'), {size: 200}); | ||
await generate(svg, resolve(__dirname, '../public/img/favicon.png'), {size: 180, removeDetail: true}); | ||
await generate(svg, resolve(__dirname, '../public/img/apple-touch-icon.png'), {size: 180, bg: true}); | ||
} | ||
|
||
main().then(exit).catch(exit); | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.