-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy path404.html
More file actions
135 lines (127 loc) · 4.37 KB
/
Copy path404.html
File metadata and controls
135 lines (127 loc) · 4.37 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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
<!DOCTYPE html>
<html>
<head>
<title>Page not found</title>
<script type="text/javascript">
window.isErrorPage = true;
window.errorCode = '404';
</script>
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta property="og:title" content="Page not found">
<script>
function getCountryAndLanguage() {
if (!window.location.pathname.match(/^\/[a-z]{2}\/[a-z]{2}_[a-z]{2}\//)) {
return { locale: 'us', language: 'en_us' };
}
const pathSegments = window.location.pathname.split('/').filter(Boolean);
const locale = pathSegments[0] || 'us';
const language = pathSegments[1] || 'en_us';
return { locale, language };
}
function setMetadata(name, content) {
const meta = document.createElement('meta');
meta.name = name;
meta.content = content;
document.head.append(meta);
}
const { locale, language } = getCountryAndLanguage();
setMetadata('nav', `/${locale}/${language}/nav/nav`);
setMetadata('footer', `/${locale}/${language}/footer/footer`);
setMetadata('nav-banners', `/${locale}/${language}/nav/nav-banners`);
setMetadata('theme', 'text-center');
</script>
<script src="/scripts/scripts.js" type="module"></script>
<script type="module">
import { sampleRUM } from '/scripts/aem.js';
sampleRUM('404', { source: document.referrer });
</script>
<style>
main.error div.section {
min-height: calc(100vh - var(--nav-height));
align-items: center;
}
.error-actions {
display: flex;
flex-wrap: wrap;
gap: var(--spacing-m, 1rem);
justify-content: center;
margin-top: var(--spacing-l, 1.5rem);
}
</style>
<link rel="stylesheet" href="/styles/styles.css">
<link rel="stylesheet" href="/styles/lazy-styles.css">
</head>
<body>
<header></header>
<main class="error">
<div class="section">
<h2 class="error-message">We're sorry that page is missing.</h2>
<div class="error-actions">
<a class="button error-home" href="/us/en_us/">Home</a>
<a class="button error-search" href="/us/en_us/search-result">Search</a>
</div>
</div>
</main>
<script>
(function injectRecipe404Widget() {
if (!window.location.pathname.includes('/recipes/')) return;
var section = document.querySelector('main.error .section');
if (!section) return;
var msg = section.querySelector('.error-message');
if (msg) msg.remove();
var actions = section.querySelector('.error-actions');
if (actions) actions.remove();
var a = document.createElement('a');
a.href = '/widgets/404/recipes';
a.textContent = a.href;
section.appendChild(a);
})();
</script>
<footer></footer>
<script>
function setDefault404NavLinks() {
var home = document.querySelector('.error-home');
var search = document.querySelector('.error-search');
if (!home && !search) return;
var loc = getCountryAndLanguage();
var base = '/' + loc.locale + '/' + loc.language;
if (home) {
home.href = base + '/';
home.title = 'Home';
}
if (search) {
search.href = base + '/search-result';
search.title = 'Search';
}
}
function localizeErrorMessage() {
const pathSegments = window.location.pathname.split('/').filter(Boolean);
const language = (pathSegments[1] || navigator.language || '').toLowerCase();
const lang = language.startsWith('fr') ? 'fr' : language.startsWith('es') ? 'es' : null;
const el = document.querySelector('.error-message');
if (el && lang) {
const messages = {
es: 'Lo sentimos, esa página no existe.',
fr: 'Nous sommes désolés, cette page est introuvable.',
};
el.textContent = messages[lang];
}
const home = document.querySelector('.error-home');
const search = document.querySelector('.error-search');
if (home && search && lang) {
const navLabels = {
es: { home: 'Inicio', search: 'Buscar' },
fr: { home: 'Accueil', search: 'Rechercher' },
};
const labels = navLabels[lang];
home.textContent = labels.home;
search.textContent = labels.search;
home.title = labels.home;
search.title = labels.search;
}
}
setDefault404NavLinks();
localizeErrorMessage();
</script>
</body>
</html>