forked from adobecom/events-milo
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathhead.html
More file actions
108 lines (92 loc) · 4.67 KB
/
Copy pathhead.html
File metadata and controls
108 lines (92 loc) · 4.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
<!-- Modifying this file will impact your performance -->
<meta name="viewport" content="width=device-width, initial-scale=1"/>
<meta name="head-loaded" content="false"/>
<script>
const userAgentMeta = document.querySelector('meta[name="hreflinksuseragents"]');
const allowedAgents = userAgentMeta && userAgentMeta.content.split(',');
const userAgentString = window.navigator.userAgent;
const isAllowedAgent = allowedAgents && allowedAgents.some((agent) => userAgentString.includes(agent.trim()));
const flagMeta = document.querySelector('meta[name="head-loaded"]');
const headAlreadyLoaded = flagMeta.content === 'true';
const LOCALES = ['ae_ar', 'ae_en', 'africa', 'ar', 'at', 'au', 'be_en', 'be_fr', 'be_nl', 'bg', 'br', 'ca_fr', 'ca', 'ch_de', 'ch_fr', 'ch_it', 'cl', 'cn', 'co', 'cr', 'cy_en', 'cz', 'de', 'dk', 'ec', 'ee', 'eg_ar', 'eg_en', 'el', 'es', 'fi', 'fr', 'gr_el', 'gr_en', 'gt', 'hk_en', 'hk_zh', 'hu', 'id_en', 'id_id', 'ie', 'il_en', 'il_he', 'in_hi', 'in', 'it', 'jp', 'kr', 'kw_ar', 'kw_en', 'la', 'langstore', 'lt', 'lu_de', 'lu_en', 'lu_fr', 'lv', 'mena_ar', 'mena_en', 'mt', 'mx', 'my_en', 'my_ms', 'ng', 'nl', 'no', 'nz', 'pe', 'ph_en', 'ph_fil', 'pl', 'pr', 'pt', 'qa_ar', 'qa_en', 'ro', 'ru', 'sa_ar', 'sa_en', 'se', 'sg', 'si', 'sk', 'th_en', 'th_th', 'tr', 'tw', 'ua', 'uk', 'vn_en', 'vn_vi', 'za'];
(() => {
function buildLink(language, url) {
const link = document.createElement('link');
link.setAttribute('rel', 'alternate');
link.setAttribute('hreflang', language);
link.setAttribute('href', url);
return link;
}
async function fetchAndParseSitemap() {
const sitemapOrigin = 'https://www.adobe.com';
const { origin, pathname } = window.location;
let sitemapPath = '/events/sitemap.xml';
const localeMatch = LOCALES.find(locale => pathname.startsWith(`/${locale}/`));
if (localeMatch) {
sitemapPath = `/${localeMatch}/events/sitemap.xml`;
}
try {
const controller = new AbortController();
const timeoutId = setTimeout(() => controller.abort(), 5000);
let response;
try {
response = await fetch(`${origin}${sitemapPath}`, { signal: controller.signal });
} finally {
clearTimeout(timeoutId);
}
if (!response.ok) {
console.warn('Failed to fetch sitemap:', response.status);
return;
}
const xmlText = await response.text();
const parser = new DOMParser();
const xmlDoc = parser.parseFromString(xmlText, 'text/xml');
const parseError = xmlDoc.querySelector('parsererror');
if (parseError) {
return;
}
const urlElements = xmlDoc.querySelectorAll('url');
let currentUrlElement = null;
const correctedPath = pathname.endsWith('.html') ? pathname : `${pathname}.html`;
const isLocalRoot = localeMatch && `${sitemapOrigin}/${localeMatch}/` === `${sitemapOrigin}${pathname}`;
const rootPage = isLocalRoot ? `${sitemapOrigin}/${localeMatch}/` : `${sitemapOrigin}/`;
const currentPageUrl = pathname !== '/' && pathname !== `/${localeMatch}/` ? `${sitemapOrigin}${correctedPath}` : `${rootPage}`;
for (const urlElement of urlElements) {
const loc = urlElement.querySelector('loc')?.textContent;
if (loc === currentPageUrl || loc === currentPageUrl.replace(/\/$/, '')) {
currentUrlElement = urlElement;
break;
}
}
if (!currentUrlElement) {
console.warn('Current page not found in sitemap');
return;
}
const alternateLinks = currentUrlElement.querySelectorAll('link[rel="alternate"]');
const linkElements = [];
alternateLinks.forEach(altLink => {
const hreflang = altLink.getAttribute('hreflang');
const href = altLink.getAttribute('href');
if (hreflang && href) {
linkElements.push(buildLink(hreflang, href));
}
});
const titleElement = document.head.querySelector('title');
if (linkElements.length > 0 && titleElement) {
titleElement.after(...linkElements);
}
} catch (error) {
console.error('Error fetching or parsing sitemap:', error);
}
}
if (isAllowedAgent && !headAlreadyLoaded) {
fetchAndParseSitemap();
}
})();
flagMeta.content = 'true';
</script>
<script src="/events/scripts/fallback.js" nomodule></script>
<script src="/events/scripts/scripts.js" type="module"></script>
<link rel="stylesheet" href="/events/styles/styles.css">
<style>body { display: none; }</style>
<link rel="icon" href="data:,">