Skip to content

Commit

Permalink
sync with latest helix-project-boilerplate
Browse files Browse the repository at this point in the history
  • Loading branch information
stefanseifert committed Aug 16, 2023
1 parent 1953835 commit ff239cb
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions scripts/lib-franklin.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,17 @@ export async function decorateIcons(element) {
return;
}
// Styled icons don't play nice with the sprite approach because of shadow dom isolation
// and same for internal references
const svg = await response.text();
if (svg.match(/(<style | class=)/)) {
ICONS_CACHE[iconName] = { styled: true, html: svg };
if (svg.match(/(<style | class=|url\(#| xlink:href="#)/)) {
ICONS_CACHE[iconName] = {
styled: true,
html: svg
// rescope ids and references to avoid clashes across icons;
.replaceAll(/ id="([^"]+)"/g, (_, id) => ` id="${iconName}-${id}"`)
.replaceAll(/="url\(#([^)]+)\)"/g, (_, id) => `="url(#${iconName}-${id})"`)
.replaceAll(/ xlink:href="#([^"]+)"/g, (_, id) => ` xlink:href="#${iconName}-${id}"`),
};
} else {
ICONS_CACHE[iconName] = {
html: svg
Expand Down

0 comments on commit ff239cb

Please sign in to comment.