Skip to content

Commit

Permalink
Add changes for 404 calls
Browse files Browse the repository at this point in the history
  • Loading branch information
Ritwik Srivastava authored and Ritwik Srivastava committed Mar 14, 2024
1 parent 1ec43d9 commit f0d416b
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
7 changes: 5 additions & 2 deletions blocks/summit-login/summit-login.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,10 +142,13 @@ waitForElement('.nav-sections[data-section-status="loaded"]').then((elm) => {

// ToDo : this part need to be udpated with decorator
function identifySecuredImages() {
document.querySelectorAll("img[loading='lazy']").forEach((img) => {
if(!img.getAttribute("width") && matchesPolarisDeliveryUrl(img.getAttribute("src"))) {
document.querySelectorAll("img[loading='eager']").forEach((img) => {
//if(!img.getAttribute("width") && matchesPolarisDeliveryUrl(img.getAttribute("src"))) {
if(img.getAttribute('src').includes(comingSoonPlaceHolder))
{
securedImages.push(img);
var srcUrl = img.getAttribute("src");
if(img.parentElement.getAttribute('data-original-source') == null)
img.parentElement.setAttribute("data-original-source", srcUrl);
}
});
Expand Down
18 changes: 17 additions & 1 deletion scripts/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import {
} from './aem.js';

const LCP_BLOCKS = []; // add your LCP blocks to the list

let comingSoonPlaceHolder = window.location.origin + "/resources/summit/coming-soon.jpeg";
/**
* Builds hero block and prepends to main in a new section.
* @param {Element} main The container element
Expand Down Expand Up @@ -121,6 +121,12 @@ function appendQueryParams(url, params) {
return url.toString();
}

function matchesPolarisDeliveryUrl(srcUrl) {
// code to match regex for host matching "delivery-pxxxx-exxxx" and URI starts with either adobe/assets/deliver or adobe/dynamicmedia/deliver
const regex = /^(https?:\/\/delivery-p[0-9]+-e[0-9-cmstg]+\.adobeaemcloud\.com\/(adobe\/assets\/deliver|adobe\/dynamicmedia\/deliver)\/(.*))/gm;
return srcUrl.match(regex) != null;
}

/**
* Creates an optimized picture element for an image.
* If the image is not an absolute URL, it will be passed to libCreateOptimizedPicture.
Expand All @@ -142,6 +148,16 @@ export function createOptimizedPicture(src, alt = '', eager = false, breakpoints
const { pathname } = url;
const ext = pathname.substring(pathname.lastIndexOf('.') + 1);

if (matchesPolarisDeliveryUrl(src)) {
// Load placeholder image
const placeholderImg = document.createElement('img');
placeholderImg.setAttribute('src', comingSoonPlaceHolder); // Set placeholder image URL
placeholderImg.setAttribute('alt', alt);
picture.setAttribute('data-original-source',src);
picture.appendChild(placeholderImg);
return picture;
}

// webp
breakpoints.forEach((br) => {
const source = document.createElement('source');
Expand Down

0 comments on commit f0d416b

Please sign in to comment.