🛠️ Implement SVG optimization utility and update getSource function to use it

This commit is contained in:
pheralb
2025-08-27 19:29:55 +01:00
parent 879f8eb10e
commit 146e8fda04
3 changed files with 42 additions and 2 deletions
+37
View File
@@ -0,0 +1,37 @@
import { optimize } from "svgo/browser";
interface OptimizeSvg {
svgCode: string;
}
export const optimizeSvg = ({ svgCode }: OptimizeSvg) => {
const svgo = optimize(svgCode, {
multipass: true,
plugins: [
"removeDimensions",
"removeXMLNS",
"removeDoctype",
"removeComments",
"removeStyleElement",
"cleanupAttrs",
"cleanupEnableBackground",
"cleanupIds",
"minifyStyles",
"removeDoctype",
"removeDesc",
"removeEmptyAttrs",
"removeEmptyText",
"removeHiddenElems",
"removeNonInheritableGroupAttrs",
"removeUnknownsAndDefaults",
"removeUselessDefs",
"removeUselessStrokeAndFill",
"removeXMLProcInst",
{
name: "removeAttrs",
params: { attrs: "(data-name|id|class)" },
},
],
});
return svgo.data;
};
+1 -1
View File
@@ -1,4 +1,4 @@
import { optimize } from "svgo";
import { optimize } from "svgo/browser";
export const getPrefixFromSvgUrl = (svgUrl: string) => {
return svgUrl.split("/").pop()!.replace(".svg", "").split("-").join("_");