1$(document).ready(function () { 2 $('.cmp-image__link').each(function () { 3 const $link = $(this); 4 let rawHref = $link.attr('data-link') || $link.attr('data-url'); 5 if (!rawHref) return; 6 7 rawHref = rawHref.trim(); 8 9 const isExternal = /^https?:\/\//.test(rawHref); 10 const isInternal = rawHref.startsWith('/content/') && !rawHref.endsWith('.html'); 11 12 // --- Extract locale from current page path ---\ 13 const origin = window.location.origin; 14 const href = window.location.href; 15 const match = href.match(/^(https?:\/\/[^\/]+\/[a-z]{2}-[a-z]{2})/i); 16 const baseWithLocale = match ? match[1] : null; 17 const currentPath = window.location.pathname; 18 const pathSegments = window.location.pathname.split('/').filter(Boolean); 19 const currentLocale = pathSegments[0] && /^[a-z]{2}([-_][a-z]{2})?$/i.test(pathSegments[0]) 20 ? pathSegments[0] 21 : null; 22 23 // --- Extract locale from data-link --- 24 function extractLocaleFromDataUrl(url) { 25 const parts = url.split('/'); 26 const homeIndex = parts.indexOf('home'); 27 28 if (homeIndex > 1) { 29 const maybeLocale = parts[homeIndex - 1]; 30 const localePattern = /^[a-z]{2}([-_][a-z]{2})?$/i; 31 32 if (localePattern.test(maybeLocale)) { 33 return maybeLocale; 34 } 35 } 36 37 return null; 38 } 39 40 let linkLocale = extractLocaleFromDataUrl(rawHref); 41 42 if (isInternal) { 43 let finalHref = rawHref; 44 45 if (currentPath.endsWith('.html') && !finalHref.endsWith('.html')) { 46 finalHref += '.html'; 47 $link.attr('href', finalHref); 48 } 49 else{ 50 linkLocale = linkLocale ? linkLocale.replace("_", "-").toLowerCase() : ""; 51 const afterHome = rawHref.split('/home/')[1]; 52 if(currentLocale && rawHref.endsWith('/home') && currentLocale == linkLocale){ 53 finalHref =baseWithLocale ; 54 55 }else if(!currentLocale && rawHref.endsWith('/home') ){ 56 finalHref = origin; 57 } 58 else if (currentLocale && !finalHref.startsWith(`/${currentLocale}`) && currentLocale == linkLocale) { 59 finalHref = baseWithLocale+'/'+afterHome; 60 } 61 else{ 62 finalHref = '/'+ afterHome; 63 } 64 $link.attr('href', finalHref); 65 } 66 67 } else if (isExternal) { 68 $link.attr('href', rawHref); 69 70 if (!$link.attr('target')) { 71 $link.attr('target', '_blank'); 72 $link.attr('rel', 'noopener noreferrer'); 73 } 74 } 75 }); 76});
Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.