mirror of
https://github.com/searxng/searxng.git
synced 2026-05-07 18:03:51 +02:00
[MOD] generate manifest PWA icons (#5859)
This commit is contained in:
@@ -18,8 +18,10 @@ export type Src2Dest = {
|
|||||||
* Convert a list of SVG files to PNG.
|
* Convert a list of SVG files to PNG.
|
||||||
*
|
*
|
||||||
* @param items - Array of SVG files (src: SVG, dest:PNG) to convert.
|
* @param items - Array of SVG files (src: SVG, dest:PNG) to convert.
|
||||||
|
* @param width - (optional) width of the PNG pictures
|
||||||
|
* @param height - (optional) height of the PNG pictures.
|
||||||
*/
|
*/
|
||||||
export const svg2png = (items: Src2Dest[]): void => {
|
export const svg2png = (items: Src2Dest[], width?: number, height?: number): void => {
|
||||||
for (const item of items) {
|
for (const item of items) {
|
||||||
fs.mkdirSync(path.dirname(item.dest), { recursive: true });
|
fs.mkdirSync(path.dirname(item.dest), { recursive: true });
|
||||||
|
|
||||||
@@ -29,6 +31,9 @@ export const svg2png = (items: Src2Dest[]): void => {
|
|||||||
compressionLevel: 9,
|
compressionLevel: 9,
|
||||||
palette: true
|
palette: true
|
||||||
})
|
})
|
||||||
|
.resize(width, height, {
|
||||||
|
fit: "contain"
|
||||||
|
})
|
||||||
.toFile(item.dest)
|
.toFile(item.dest)
|
||||||
.then((info) => {
|
.then((info) => {
|
||||||
console.log(`[svg2png] created ${item.dest} -- bytes: ${info.size}, w:${info.width}px, h:${info.height}px`);
|
console.log(`[svg2png] created ${item.dest} -- bytes: ${info.size}, w:${info.width}px, h:${info.height}px`);
|
||||||
|
|||||||
@@ -17,13 +17,15 @@ import { type Src2Dest, svg2png, svg2svg } from "./img.ts";
|
|||||||
* Vite plugin to convert a list of SVG files to PNG.
|
* Vite plugin to convert a list of SVG files to PNG.
|
||||||
*
|
*
|
||||||
* @param items - Array of SVG files (src: SVG, dest:PNG) to convert.
|
* @param items - Array of SVG files (src: SVG, dest:PNG) to convert.
|
||||||
|
* @param width - (optional) width of the PNG picture
|
||||||
|
* @param height - (optional) height of the PNG picture
|
||||||
*/
|
*/
|
||||||
export const plg_svg2png = (items: Src2Dest[]): Plugin => {
|
export const plg_svg2png = (items: Src2Dest[], width?: number, height?: number): Plugin => {
|
||||||
return {
|
return {
|
||||||
name: "searxng-simple-svg2png",
|
name: "searxng-simple-svg2png",
|
||||||
apply: "build",
|
apply: "build",
|
||||||
writeBundle: () => {
|
writeBundle: () => {
|
||||||
svg2png(items);
|
svg2png(items, width, height);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -132,6 +132,28 @@ export default {
|
|||||||
}
|
}
|
||||||
]),
|
]),
|
||||||
|
|
||||||
|
// SearXNG PWA Icons (static)
|
||||||
|
plg_svg2png(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
src: `${PATH.brand}/searxng-wordmark.svg`,
|
||||||
|
dest: `${PATH.dist}/img/512.png`
|
||||||
|
}
|
||||||
|
],
|
||||||
|
512,
|
||||||
|
512
|
||||||
|
),
|
||||||
|
plg_svg2png(
|
||||||
|
[
|
||||||
|
{
|
||||||
|
src: `${PATH.brand}/searxng-wordmark.svg`,
|
||||||
|
dest: `${PATH.dist}/img/192.png`
|
||||||
|
}
|
||||||
|
],
|
||||||
|
192,
|
||||||
|
192
|
||||||
|
),
|
||||||
|
|
||||||
// -- svg
|
// -- svg
|
||||||
plg_svg2svg(
|
plg_svg2svg(
|
||||||
[
|
[
|
||||||
|
|||||||
Reference in New Issue
Block a user