Skip to content

Remove "title" node from svg icons during build #2578

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

Merged
merged 3 commits into from
Nov 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,6 @@ Go to these links to find documentation about [the Flexbox component](src/compon

1. Your svg file has to be exported with a `viewBox="0 0 512 512"`.
2. Clean up the file: keep only `xmlns` and `viewBox` attributes on `svg` tag and remove the rest (eventually you can use `data-fixedcolors` attribute on `svg` icon which has to have fixed colors for some reason). There is no need to optimize a `<path>` since it will be optimized during build process with [svgo](https://www.npmjs.com/package/svgo).
3. Remove the title.

Now, your file should look like:

Expand Down
6 changes: 6 additions & 0 deletions scripts/tasks/svgs-generate.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,13 @@ function svgSymbolCleanUp(config, shape, sprite, callback) {
childNodes[i].removeAttribute('fill');
}
}

if (childNodes[i].nodeName === 'title') {
symbol.removeChild(childNodes[i]);
i--;
}
}

callback(null);
}

Expand Down
10 changes: 5 additions & 5 deletions svgo.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@ const removeClass = {

module.exports = {
subjectIcons: {
plugins: [],
plugins: ['removeTitle'],
},
subjectMonoIcons: {
plugins: [removeClass, removeFillNonFixedColors],
plugins: [removeClass, removeFillNonFixedColors, 'removeTitle'],
},
icons: {
plugins: [removeClass, removeFillNonFixedColors],
plugins: [removeClass, removeFillNonFixedColors, 'removeTitle'],
},
mathSymbols: {
plugins: [removeClass, removeFillNonFixedColors],
plugins: [removeClass, removeFillNonFixedColors, 'removeTitle'],
},
mobileIcons: {
plugins: [removeClass, removeFillNonFixedColors],
plugins: [removeClass, removeFillNonFixedColors, 'removeTitle'],
},
};