Skip to content

Commit

Permalink
feat: add support from DAM SVG icon loading
Browse files Browse the repository at this point in the history
  • Loading branch information
mhaack committed Dec 12, 2023
1 parent 6dc16b0 commit 4cb3b1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
8 changes: 7 additions & 1 deletion scripts/lib-franklin.js
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,13 @@ export async function decorateIcons(element) {
if (!ICONS_CACHE[iconName]) {
ICONS_CACHE[iconName] = true;
try {
const response = await fetch(`${window.hlx.codeBasePath}/icons/${iconName}.svg`);
let iconSource = `${window.hlx.codeBasePath}/icons/${iconName}.svg`;
if (iconName.startsWith('dam-')) {
const isPublicDomain = window.location.hostname.includes('lifesciences.danaher.com');
iconSource = isPublicDomain ? '' : 'https://lifesciences.danaher.com';
iconSource += `/content/dam/danaher/system/icons/${iconName.substring(4).replace('_', ' ')}.svg`;
}
const response = await fetch(iconSource);
if (!response.ok) {
ICONS_CACHE[iconName] = false;
return;
Expand Down
2 changes: 2 additions & 0 deletions tools/importer/transformers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import miniTeaser from './miniTeaser.js';
import productCategoryList from './productCategoryList.js';
import opcoHomeArticlesList from './opcoHomeArticlesList.js';
import socialFeeds from './socialFeeds.js';
import postProcessSVGIcons from './postProcessSVGIcons.js';

// eslint-disable-next-line import/prefer-default-export
export const transformers = [
Expand Down Expand Up @@ -89,5 +90,6 @@ export const preTransformers = [
];

export const postTransformers = [
postProcessSVGIcons,
metadata,
];
13 changes: 13 additions & 0 deletions tools/importer/transformers/postProcessSVGIcons.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/*
* Convert all /content/dam/danaher/system/icons/... icons to SVG placeholders
*/
const postProcessSVGIcons = (main) => {
main.querySelectorAll('img').forEach((img) => {
const imgSrc = img.getAttribute('src');
if (imgSrc.includes('/content/dam/danaher/system/icons/') && imgSrc.includes('.svg')) {
const svgFileName = imgSrc.split('/').pop().split('.')[0].replace(' ', '_');
img.outerHTML = `:dam-${svgFileName}:`;
}
});
};
export default postProcessSVGIcons;

0 comments on commit 4cb3b1e

Please sign in to comment.