Closed tedw closed 1 year ago
I guess the class names gets prefixed with a letter (in my case, it's an "a") because of svg-sprite svg.namespaceClassnames (https://github.com/svg-sprite/svg-sprite/blob/main/docs/configuration.md#sprite-svg-options) default option:
"In order to avoid CSS class name ambiguities, the default behavior is to namespace CSS class names in the source SVGs before compiling them into a sprite. Each class name is prepended with a unique string."
So whoever needs it just pass this option as false and the class names won't be modified.
As for the default options getting overridden it happens because in line 18 of the .eleventy.js file (https://github.com/patrickxchong/eleventy-plugin-svg-sprite/blob/main/.eleventy.js#L18) the Object.assign() method makes a shallow copy of target (defaultOptions) object so its nested values aren't being copied, then the code breaks because at line 71 of the SVGSprite file https://github.com/patrickxchong/eleventy-plugin-svg-sprite/blob/main/src/SVGSprite.js#L71 since the spriteConfig.mode becomes undefined. I guess it would be interesting to change it with a deep merging logic instead or maybe making it explicit that it's necessary to copy the default options of spriteConfig in case one wants to modify/add new options
@ivanahcosta Thanks for looking into that!
Hello @tedw my humble apologies for the late revert, it's been a busy season. Thanks a lot @ivanahcosta for debugging the source of the issue. I tried a few deep merge methods on the web but they didn't work well so I resorted to using lodash's merge method instead.
Have published the fixed version 2.4.1
on npm and created a working example at https://github.com/patrickxchong/eleventy-plugin-svg-sprite/tree/main/demo/custom_spriteconfig with the use case you shared earlier @tedw.
Hope this helps! Can close this issue if you've tested the new version works as expected.
@patrickxchong No apologies necessary. I appreciate the update, and your work on the plugin! 🙏
You're most welcome. Closing the issue now
It seems changing any defaults in
spriteConfig
causes all of the options to be overwritten. I was just trying to make a change to SVGO’s settings but had to redefine everything listed in options.js. Below is an explanation of my original issue and how I went about fixing it.I noticed any
<g>
tags in my SVGs were removed in the sprite, with their attributes applied to all children.Here’s an example:
Here’s the inline sprite output:
Turns out this was because svg-sprite uses the default SVGO settings, which set
collapseGroups
totrue
.I first tried adding this config info but got an error when booting Eleventy:
Error message:
So then I tried redefining all of the default
spriteConfig
options, which worked:For some reason, though, all of my class names are being prefixed with
d
. I can’t seem to figure out how to disable that but luckily I don’t need classes on my SVGs.Anyway, thanks for building this plugin! Aside from this minor issue it’s been working great on a couple of projects.