Skip to content

Commit

Permalink
Added cheerio to modify SVG attributes
Browse files Browse the repository at this point in the history
Cheerio was added to the .eleventy.js script to help modify SVG attributes. This was done to remove the icon from the accessibility tree for better user experience. Thanks to @FlorianBoe for the suggestion.
  • Loading branch information
reatlat committed Apr 21, 2024
1 parent c48854a commit 7fa8964
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion .eleventy.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
const feather = require('feather-icons');
const cheerio = require('cheerio');

module.exports = (eleventyConfig, attributes = {}) => {

Expand Down Expand Up @@ -26,6 +27,13 @@ module.exports = (eleventyConfig, attributes = {}) => {

attributes = { ...globalAttributes, ...attributes };

return feather.icons[iconName].toSvg(attributes)
const $ = cheerio.load(feather.icons[iconName].toSvg(attributes), {
xmlMode: true
});

// Remove the icon from the accessibility tree. TY to @FlorianBoe
$(`svg`).attr(`aria-hidden`, 'true');

return $.html().trim();
});
};

0 comments on commit 7fa8964

Please sign in to comment.