FWeinb / grunt-svgstore

Merge svgs from a folder
MIT License
920 stars 94 forks source link

Does not test for duplicate icons #99

Open betsydupuis opened 9 years ago

betsydupuis commented 9 years ago

It is possible to produce duplicate svgs specifying files with the same name in different directories

gruntfile.js

    svgstore: {
      defaults: {
        options: {
        },
        files: {
          'tmp/default_options.svg': ['test/fixtures/codepen.svg',
                                                     'test/fixtures/remote/codepen.svg']
        },
      },

Result SVG

<svg xmlns="http://www.w3.org/2000/svg">
    <symbol viewBox="0 0 100 100" id="codepen">
        <title>Codepen Icon</title>
        <desc>This is the offical Codepen icon</desc>
        ...
    </symbol>
    <symbol viewBox="0 0 100 100" id="codepen">
        <title>Codepen Icon</title>
        <desc>This is the offical Codepen icon</desc>
        ...
    </symbol>
</svg>
IanLunn commented 9 years ago

On running the task multiple times, it'll also add the same icon to the output file each time. Should it clear the output file before adding definitions again?

betsydupuis commented 9 years ago

Maybe output an error?

Another away to deal with it would be for:

        files: {
          'tmp/default_options.svg': ['test/fixtures/codepen.svg',
                                                     'test/fixtures/remote/codepen.svg']
        },

To output:

<svg xmlns="http://www.w3.org/2000/svg">
    <symbol viewBox="0 0 100 100" id="codepen">
        <title>Codepen Icon</title>
        <desc>This is the offical Codepen icon</desc>
        ...
    </symbol>
   <!------- Add the remote directory as prepended part of the name/id ------->
    <symbol viewBox="0 0 100 100" id="remote-codepen">
        <title>Remote Codepen Icon</title>
        <desc>This is the offical Codepen icon</desc>
        ...
    </symbol>
</svg>

A real world example would be attempting to compile two icon sets into one sprite sheet. Personally, I'm maintaining legacy icons while trying to minify the icon set.

Samic8 commented 9 years ago

The thing is that although the files may be of the same name, generating the same ID. They could be completely different svgs, which the naming being the only similarity. I am thinking the error message might be the best way to deal with it.

betsydupuis commented 9 years ago

@Samic8 Yes, I think an error output would accommodate most situations.

biser-yordanov commented 5 years ago

Just proposed a possible solution, which works for a project of mine with Pull Request #143