patrickxchong / eleventy-plugin-svg-sprite

A high performance Eleventy universal plugin that compiles a directory of SVG files into a single SVG Sprite and adds shortcodes to embed SVG Sprite and SVG content in Eleventy templates.
MIT License
39 stars 6 forks source link

Change in sprite naming convention regarding subdirectories #8

Closed tylercampbell closed 2 years ago

tylercampbell commented 2 years ago

Just wanted to give a heads up that in 1.22 and older, subdirectories were a part of the sprite's naming convention. I believe 1.3.1 (or 1.3.0) changed this behavior.

  eleventyConfig.addPlugin(svgSprite, {
    path: "./src/assets/svg",
  });

Old behavior: ./src/assets/svg/menu/close.svg = {% svg "menu--close" %}

New behavior: ./src/assets/svg/menu/close.svg = {% svg "close" %}

I'm not sure if the old behavior was explicitly documented or if using subdirectories is even advised but I did want to share this info for anyone else who encounters it.

patrickxchong commented 2 years ago

Thanks for raising the issue @tylercampbell. I've not used the plugin with subdirectories before so have never had to account for this case. If you have the time I'd appreciate if you could check and pin down the exact version that introduced the issue else I'll look into this in the upcoming weekend.

tylercampbell commented 2 years ago

Thanks @patrickxchong. I've narrowed it down to 1.3.1 so I'm guessing the change came with svg-sprite 2.0

I only had time to do a quick search but couldn't find any relevant info in their docs or issues so I may be the only person using subdirectories.

I've got no problem updating my code to match the new convention so we can close this issue if you'd like.

patrickxchong commented 2 years ago

Hey @tylercampbell I think I may have found the issue, screenshots below for reference. I hope that this can be easily fixed by adding separator: '--' to the config. I'll test this tomorrow and if it works I'll publish a new version with updated documentation. I do think keeping the '--' behaviour is better esp for people who prefer namespacing through directories.

SVG Sprite Docs

image image

Current plugin config

image

patrickxchong commented 2 years ago

@tylercampbell when you have the time can you update the plugin to v2.0.0 and give it a try? (made it a major release in case there are people using subdirectories but relied on not having the subdirectory in the id). You should be able to get back the old behaviour. Let me know if it does/doesn't!

tylercampbell commented 2 years ago

@patrickxchong Just tested. Everything works as expected with 2.0. Thank you so much for your work on this! It's much appreciated.

image

patrickxchong commented 2 years ago

Great, glad it worked out! 😄 I'll close this issue now. Have a good weekend!