-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Repeated values in class names #1133
Comments
Copied this PR, but removed the extra changes |
Fixed in 2.0.1 |
@TrySound was excited to come back to the fold, but I just tried using {
"plugins": [
{
"addAttributesToSVGElement": {
"attributes": [{ "aria-hidden": "true" }]
}
},
{
"prefixIds": {
"delim": "_"
}
},
{
"cleanupIDs": { "minify": true }
},
{ "cleanupListOfValues": true },
{ "convertColors": true },
{ "convertStyleToAttrs": true },
{ "convertTransform": true },
{ "mergePaths": true },
{ "minifyStyles": true },
{ "moveElemesAttrsToGroup": true },
{
"removeAttrs": true,
"params": { "attrs": ["fill-rule", "fillRule"] }
},
{ "removeComments": true },
{ "removeDesc": true, "params": { "removeAny": true } },
{ "removeDimensions": true },
{ "removeDoctype": true },
{ "removeEditorsNSData": true },
{ "removeEmptyAttrs": true },
{ "removeEmptyContainers": true },
{ "removeEmptyText": true },
{ "removeNonInheritableGroupAttrs": true },
{ "removeTitle": true },
{ "removeUnknownsAndDefaults": true },
{ "removeUnusedNS": true },
{ "removeUselessDefs": true },
{ "removeUselessStrokeAndFill": true },
{ "removeXMLProcInst": true },
{ "sortAttrs": true }
],
"floatPrecision": 3,
"multipass": true
} still leads to a class being duplicated upon an SVG For example: Run <svg xmlns="http://www.w3.org/2000/svg" aria-hidden="true" viewBox="0 0 32 32">
<path fill="currentColor" d="M8 26.573l4-6.667h16l-4 6.667H8z" class="GoogleDrive_svg_path1"/>
<path fill="currentColor" d="M20 19.906h8L20 6.573h-8l8 13.333z" class="GoogleDrive_svg_path2"/>
<path fill="currentColor" d="M4 19.906l4 6.667 8-13.333-4-6.667-8 13.333z" class="GoogleDrive_svg_path3"/>
</svg> yields <path fill="currentColor" d="M8 26.573l4-6.667h16l-4 6.667H8z" class="GoogleDrive_svg_GoogleDrive_svg_GoogleDrive_svg_path1"/>
<path fill="currentColor" d="M20 19.906h8L20 6.573h-8l8 13.333z" class="GoogleDrive_svg_GoogleDrive_svg_GoogleDrive_svg_path2"/>
<path fill="currentColor" d="M4 19.906l4 6.667 8-13.333-4-6.667-8 13.333z" class="GoogleDrive_svg_GoogleDrive_svg_GoogleDrive_svg_path3"/> |
Hi! Configuration is changed in v2. See https://github.com/svg/svgo/releases/tag/v2.0.0 const { extendDefaultPlugins } = require('svgo');
module.exports = {
"plugins": extendDefaultPlugins([
{
name: "addAttributesToSVGElement",
params: {
"attributes": [{ "aria-hidden": "true" }]
}
},
{
name: "prefixIds",
params: {
"delim": "_"
}
},
{
name: "cleanupIDs", params: { "minify": true }
},
"cleanupListOfValues",
"convertColors",
"convertStyleToAttrs",
"convertTransform",
"mergePaths",
"minifyStyles",
"moveElemesAttrsToGroup",
{
name: "removeAttrs",
params: { attrs: ["fill-rule", "fillRule"] }
},
"removeComments",
{ name: "removeDesc", params: { removeAny: true } },
"removeDimensions",
"removeDoctype",
"removeEditorsNSData",
"removeEmptyAttrs",
"removeEmptyContainers",
"removeEmptyText",
"removeNonInheritableGroupAttrs",
"removeTitle",
"removeUnknownsAndDefaults",
"removeUnusedNS",
"removeUselessDefs",
"removeUselessStrokeAndFill",
"removeXMLProcInst",
"sortAttrs",
]),
"floatPrecision": 3,
"multipass": true
} |
Great catch! Adjusted accordingly, but ran into #1358 |
Circling back... I forced the version of SVGO to v2 via Unfortunately, I'm still seeing classnames continuing to be edited on each SVGO CLI command. Proof there's only SVGOv2:Beginning:After 1st
|
I see. Well, this is expected behaviour. If you want to have better optimized svg use |
Is there anything against merging a PR like #1135 which prevents prepending class name if it's already added? |
It may be unreliable in case if prefix matches actual id. |
What about checking for that situation? I'm surprised classes get prefixed when Sorry if my persistence is frustrating... I'm more curious than anything. I use classnames to bypass path merging on a per-file basis and - sometimes - I run SVGO against all my files. It seems like the classname attribute is the only one that returns differently on each run even if they've already been optimized. It seems my only recourse for now is to never run SVGO against all files. |
I agree naming is not very reliable. Though there is an option to disable or id or classnames prefixing
|
Use
--multipass
option and{"prefixIds":true}
creates css class names with repeated values.For example run
svgo hello3.svg -o - --pretty --config='{"plugins":[{"prefixIds":true}]}' --multipass
using the svg filehello3.svg
:Creates this svg:
As you can see, class names contains the name file duplicated different times (
hello3_svg__hello3_svg__hello3_svg__cls-1
).This PR should solve the problem.
The text was updated successfully, but these errors were encountered: