@easy-web/core 1.3.3 → 1.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -0
- package/package.json +9 -9
- package/src/components/Header.astro +205 -205
- package/src/components/HeaderCentered.astro +230 -230
- package/src/components/HeaderFlyout.astro +370 -370
- package/src/components/HeaderHideOnScroll.astro +234 -234
- package/src/components/LanguageSwitch.astro +82 -82
- package/src/components/NotFound.astro +115 -115
- package/src/components/PageShell.astro +82 -82
- package/src/components/SeoHead.astro +106 -106
- package/src/components/StructuredData.astro +1 -1
- package/src/components/ThemeToggle.astro +84 -84
- package/src/components/UniversalMedia.astro +106 -106
- package/src/components/__tests__/StructuredData.test.ts +1 -1
- package/src/components/__tests__/UniversalMedia.test.ts +65 -65
- package/src/contracts/__tests__/jsonld.test.ts +1 -1
- package/src/contracts/index.ts +1 -1
- package/src/contracts/jsonld.ts +1 -1
- package/src/i18n/__tests__/factory.test.ts +54 -54
- package/src/i18n/__tests__/localized-paths.test.ts +258 -258
- package/src/i18n/__tests__/routing-multi-locale.test.ts +89 -89
- package/src/i18n/__tests__/seo.test.ts +140 -140
- package/src/i18n/factory.ts +66 -66
- package/src/i18n/index.ts +5 -5
- package/src/i18n/localized-paths.ts +181 -181
- package/src/i18n/seo.ts +131 -131
- package/src/markdown/__tests__/__fixtures__/abs-src-assets.md +1 -1
- package/src/markdown/__tests__/__fixtures__/external-url.md +1 -1
- package/src/markdown/__tests__/__fixtures__/public-slash.md +1 -1
- package/src/markdown/__tests__/__fixtures__/rel-double-dot.md +1 -1
- package/src/markdown/__tests__/index.test.ts +60 -60
- package/src/markdown/index.ts +1 -1
- package/src/markdown/plugin.ts +42 -42
- package/src/schemas/__tests__/notFound.test.ts +32 -32
- package/src/schemas/notFound.ts +33 -33
- package/src/seo/__tests__/crawl-policy.test.ts +50 -50
- package/src/seo/__tests__/integration.test.ts +195 -195
- package/src/seo/__tests__/no-index-resolution.test.ts +53 -53
- package/src/seo/__tests__/robots-txt.test.ts +66 -66
- package/src/seo/__tests__/sitemap-options.test.ts +400 -400
- package/src/seo/crawl-policy.ts +36 -36
- package/src/seo/index.ts +254 -254
- package/src/seo/routes/robots-txt.ts +36 -36
|
@@ -1,234 +1,234 @@
|
|
|
1
|
-
---
|
|
2
|
-
import type { HeaderHideOnScrollProps } from '../contracts/props.js';
|
|
3
|
-
import { resolveLabels } from './labels.js';
|
|
4
|
-
import Media from './Media.astro';
|
|
5
|
-
import ThemeToggle from './ThemeToggle.astro';
|
|
6
|
-
import LanguageSwitch from './LanguageSwitch.astro';
|
|
7
|
-
|
|
8
|
-
export type Props = HeaderHideOnScrollProps;
|
|
9
|
-
|
|
10
|
-
const { lang = 'en', labels: labelOverrides } = Astro.props;
|
|
11
|
-
const labels = resolveLabels(lang, labelOverrides);
|
|
12
|
-
const { siteName, navItems, currentLang, pathname, alternateHref, menuLabel = labels.toggleNavigationMenu, logo, navId = 'ew-header-hos-nav', locales } = Astro.props;
|
|
13
|
-
const showLanguageSwitch = !locales || locales.length > 1;
|
|
14
|
-
// A bare logo URL keeps today's markup: the site name is its alt text.
|
|
15
|
-
const logoImage = !logo ? undefined : typeof logo === 'string' ? { src: logo, alt: siteName } : logo;
|
|
16
|
-
---
|
|
17
|
-
|
|
18
|
-
<header class="ew-header-hide-on-scroll" data-testid="header-hide-on-scroll">
|
|
19
|
-
<div class="ew-header-hide-on-scroll__inner">
|
|
20
|
-
<a href={currentLang === 'de' ? '/' : `/${currentLang}/`} class="ew-header-hide-on-scroll__brand">
|
|
21
|
-
{logoImage ? <Media image={logoImage} class="ew-header-hide-on-scroll__logo" /> : siteName}
|
|
22
|
-
</a>
|
|
23
|
-
|
|
24
|
-
<button
|
|
25
|
-
type="button"
|
|
26
|
-
class="ew-header-hide-on-scroll__menu-btn"
|
|
27
|
-
aria-label={menuLabel}
|
|
28
|
-
aria-expanded="false"
|
|
29
|
-
aria-controls={navId}
|
|
30
|
-
data-testid="mobile-menu-toggle"
|
|
31
|
-
>
|
|
32
|
-
<svg class="ew-header-hide-on-scroll__menu-icon ew-header-hide-on-scroll__menu-icon--open" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
|
|
33
|
-
<line x1="3" y1="6" x2="21" y2="6"></line>
|
|
34
|
-
<line x1="3" y1="12" x2="21" y2="12"></line>
|
|
35
|
-
<line x1="3" y1="18" x2="21" y2="18"></line>
|
|
36
|
-
</svg>
|
|
37
|
-
<svg class="ew-header-hide-on-scroll__menu-icon ew-header-hide-on-scroll__menu-icon--close" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
|
|
38
|
-
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
39
|
-
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
40
|
-
</svg>
|
|
41
|
-
</button>
|
|
42
|
-
|
|
43
|
-
<nav id={navId} class="ew-header-hide-on-scroll__nav" aria-label={labels.mainNavigation}>
|
|
44
|
-
<ul class="ew-header-hide-on-scroll__links">
|
|
45
|
-
{navItems.map((item) => (
|
|
46
|
-
<li>
|
|
47
|
-
<a href={item.href} class:list={['ew-header-hide-on-scroll__link', { 'ew-header-hide-on-scroll__link--active': pathname === item.href }]}>
|
|
48
|
-
{item.label}
|
|
49
|
-
</a>
|
|
50
|
-
</li>
|
|
51
|
-
))}
|
|
52
|
-
</ul>
|
|
53
|
-
<div class="ew-header-hide-on-scroll__actions">
|
|
54
|
-
<slot name="actions">
|
|
55
|
-
<ThemeToggle lang={lang} labels={labelOverrides} />
|
|
56
|
-
{showLanguageSwitch && <LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} lang={lang} labels={labelOverrides} />}
|
|
57
|
-
</slot>
|
|
58
|
-
</div>
|
|
59
|
-
</nav>
|
|
60
|
-
</div>
|
|
61
|
-
</header>
|
|
62
|
-
|
|
63
|
-
<style>
|
|
64
|
-
.ew-header-hide-on-scroll {
|
|
65
|
-
position: fixed;
|
|
66
|
-
top: 0;
|
|
67
|
-
left: 0;
|
|
68
|
-
right: 0;
|
|
69
|
-
z-index: 100;
|
|
70
|
-
transition: transform 0.3s ease;
|
|
71
|
-
background: var(--ew-surface);
|
|
72
|
-
border-bottom: 1px solid var(--ew-border);
|
|
73
|
-
}
|
|
74
|
-
.ew-header-hide-on-scroll--hidden {
|
|
75
|
-
transform: translateY(-100%);
|
|
76
|
-
}
|
|
77
|
-
.ew-header-hide-on-scroll__inner {
|
|
78
|
-
display: flex;
|
|
79
|
-
align-items: center;
|
|
80
|
-
justify-content: space-between;
|
|
81
|
-
max-width: 72rem;
|
|
82
|
-
margin: 0 auto;
|
|
83
|
-
padding: var(--ew-space-3) var(--ew-space-5);
|
|
84
|
-
}
|
|
85
|
-
.ew-header-hide-on-scroll__brand {
|
|
86
|
-
font-family: var(--ew-font-sans);
|
|
87
|
-
font-size: var(--ew-text-lg);
|
|
88
|
-
font-weight: 700;
|
|
89
|
-
color: var(--ew-on-surface);
|
|
90
|
-
text-decoration: none;
|
|
91
|
-
letter-spacing: -0.01em;
|
|
92
|
-
}
|
|
93
|
-
.ew-header-hide-on-scroll__brand:hover {
|
|
94
|
-
color: var(--ew-primary);
|
|
95
|
-
}
|
|
96
|
-
.ew-header-hide-on-scroll__logo {
|
|
97
|
-
height: 1.5rem;
|
|
98
|
-
width: auto;
|
|
99
|
-
display: block;
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
.ew-header-hide-on-scroll__menu-btn {
|
|
103
|
-
display: none;
|
|
104
|
-
background: transparent;
|
|
105
|
-
border: none;
|
|
106
|
-
color: var(--ew-on-surface);
|
|
107
|
-
cursor: pointer;
|
|
108
|
-
padding: var(--ew-space-1);
|
|
109
|
-
}
|
|
110
|
-
.ew-header-hide-on-scroll__menu-btn:focus-visible {
|
|
111
|
-
outline: 2px solid var(--ew-primary);
|
|
112
|
-
outline-offset: 2px;
|
|
113
|
-
}
|
|
114
|
-
.ew-header-hide-on-scroll__menu-icon--close { display: none; }
|
|
115
|
-
|
|
116
|
-
.ew-header-hide-on-scroll__nav {
|
|
117
|
-
display: flex;
|
|
118
|
-
align-items: center;
|
|
119
|
-
gap: var(--ew-space-5);
|
|
120
|
-
}
|
|
121
|
-
.ew-header-hide-on-scroll__links {
|
|
122
|
-
display: flex;
|
|
123
|
-
list-style: none;
|
|
124
|
-
margin: 0;
|
|
125
|
-
padding: 0;
|
|
126
|
-
gap: var(--ew-space-1);
|
|
127
|
-
}
|
|
128
|
-
.ew-header-hide-on-scroll__link {
|
|
129
|
-
display: block;
|
|
130
|
-
padding: var(--ew-space-2) var(--ew-space-3);
|
|
131
|
-
border-radius: var(--ew-radius-md);
|
|
132
|
-
color: var(--ew-muted);
|
|
133
|
-
font-family: var(--ew-font-sans);
|
|
134
|
-
font-size: var(--ew-text-sm);
|
|
135
|
-
font-weight: 500;
|
|
136
|
-
text-decoration: none;
|
|
137
|
-
}
|
|
138
|
-
.ew-header-hide-on-scroll__link:hover {
|
|
139
|
-
color: var(--ew-on-surface);
|
|
140
|
-
background: var(--ew-surface-muted);
|
|
141
|
-
}
|
|
142
|
-
.ew-header-hide-on-scroll__link--active {
|
|
143
|
-
color: var(--ew-on-surface);
|
|
144
|
-
background: var(--ew-surface-muted);
|
|
145
|
-
}
|
|
146
|
-
.ew-header-hide-on-scroll__actions {
|
|
147
|
-
display: flex;
|
|
148
|
-
align-items: center;
|
|
149
|
-
gap: var(--ew-space-2);
|
|
150
|
-
border-left: 1px solid var(--ew-border);
|
|
151
|
-
padding-left: var(--ew-space-3);
|
|
152
|
-
margin-left: var(--ew-space-1);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
@media (max-width: 768px) {
|
|
156
|
-
.ew-header-hide-on-scroll__menu-btn {
|
|
157
|
-
display: flex;
|
|
158
|
-
}
|
|
159
|
-
.ew-header-hide-on-scroll__nav {
|
|
160
|
-
display: none;
|
|
161
|
-
position: absolute;
|
|
162
|
-
top: 100%;
|
|
163
|
-
left: 0;
|
|
164
|
-
right: 0;
|
|
165
|
-
flex-direction: column;
|
|
166
|
-
background: var(--ew-surface);
|
|
167
|
-
border-bottom: 1px solid var(--ew-border);
|
|
168
|
-
padding: var(--ew-space-4) var(--ew-space-5);
|
|
169
|
-
gap: var(--ew-space-4);
|
|
170
|
-
}
|
|
171
|
-
.ew-header-hide-on-scroll__nav[data-open] {
|
|
172
|
-
display: flex;
|
|
173
|
-
}
|
|
174
|
-
.ew-header-hide-on-scroll__links {
|
|
175
|
-
flex-direction: column;
|
|
176
|
-
gap: var(--ew-space-1);
|
|
177
|
-
}
|
|
178
|
-
.ew-header-hide-on-scroll__actions {
|
|
179
|
-
border-left: none;
|
|
180
|
-
padding-left: 0;
|
|
181
|
-
margin-left: 0;
|
|
182
|
-
padding-top: var(--ew-space-3);
|
|
183
|
-
border-top: 1px solid var(--ew-border);
|
|
184
|
-
}
|
|
185
|
-
.ew-header-hide-on-scroll__menu-btn[aria-expanded="true"] .ew-header-hide-on-scroll__menu-icon--open { display: none; }
|
|
186
|
-
.ew-header-hide-on-scroll__menu-btn[aria-expanded="true"] .ew-header-hide-on-scroll__menu-icon--close { display: block; }
|
|
187
|
-
}
|
|
188
|
-
</style>
|
|
189
|
-
|
|
190
|
-
<script>
|
|
191
|
-
function initHeader(headerEl: Element) {
|
|
192
|
-
const applyPadding = () => {
|
|
193
|
-
document.body.style.paddingTop = `${headerEl.getBoundingClientRect().height}px`;
|
|
194
|
-
};
|
|
195
|
-
applyPadding();
|
|
196
|
-
|
|
197
|
-
let lastScrollY = window.scrollY;
|
|
198
|
-
let ticking = false;
|
|
199
|
-
|
|
200
|
-
const handleScroll = () => {
|
|
201
|
-
if (!ticking) {
|
|
202
|
-
window.requestAnimationFrame(() => {
|
|
203
|
-
const currentScrollY = window.scrollY;
|
|
204
|
-
if (currentScrollY > lastScrollY && currentScrollY > 80) {
|
|
205
|
-
headerEl.classList.add('ew-header-hide-on-scroll--hidden');
|
|
206
|
-
} else {
|
|
207
|
-
headerEl.classList.remove('ew-header-hide-on-scroll--hidden');
|
|
208
|
-
}
|
|
209
|
-
lastScrollY = currentScrollY;
|
|
210
|
-
ticking = false;
|
|
211
|
-
});
|
|
212
|
-
ticking = true;
|
|
213
|
-
}
|
|
214
|
-
};
|
|
215
|
-
|
|
216
|
-
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
217
|
-
window.addEventListener('resize', applyPadding);
|
|
218
|
-
|
|
219
|
-
const resizeObserver = 'ResizeObserver' in window ? new ResizeObserver(applyPadding) : null;
|
|
220
|
-
resizeObserver?.observe(headerEl);
|
|
221
|
-
|
|
222
|
-
const btn = headerEl.querySelector('.ew-header-hide-on-scroll__menu-btn') as HTMLButtonElement | null;
|
|
223
|
-
const nav = headerEl.querySelector('.ew-header-hide-on-scroll__nav') as HTMLElement | null;
|
|
224
|
-
if (btn && nav) {
|
|
225
|
-
btn.addEventListener('click', () => {
|
|
226
|
-
const isOpen = btn.getAttribute('aria-expanded') === 'true';
|
|
227
|
-
btn.setAttribute('aria-expanded', String(!isOpen));
|
|
228
|
-
if (isOpen) nav.removeAttribute('data-open');
|
|
229
|
-
else nav.setAttribute('data-open', '');
|
|
230
|
-
});
|
|
231
|
-
}
|
|
232
|
-
}
|
|
233
|
-
document.querySelectorAll('.ew-header-hide-on-scroll').forEach(initHeader);
|
|
234
|
-
</script>
|
|
1
|
+
---
|
|
2
|
+
import type { HeaderHideOnScrollProps } from '../contracts/props.js';
|
|
3
|
+
import { resolveLabels } from './labels.js';
|
|
4
|
+
import Media from './Media.astro';
|
|
5
|
+
import ThemeToggle from './ThemeToggle.astro';
|
|
6
|
+
import LanguageSwitch from './LanguageSwitch.astro';
|
|
7
|
+
|
|
8
|
+
export type Props = HeaderHideOnScrollProps;
|
|
9
|
+
|
|
10
|
+
const { lang = 'en', labels: labelOverrides } = Astro.props;
|
|
11
|
+
const labels = resolveLabels(lang, labelOverrides);
|
|
12
|
+
const { siteName, navItems, currentLang, pathname, alternateHref, menuLabel = labels.toggleNavigationMenu, logo, navId = 'ew-header-hos-nav', locales } = Astro.props;
|
|
13
|
+
const showLanguageSwitch = !locales || locales.length > 1;
|
|
14
|
+
// A bare logo URL keeps today's markup: the site name is its alt text.
|
|
15
|
+
const logoImage = !logo ? undefined : typeof logo === 'string' ? { src: logo, alt: siteName } : logo;
|
|
16
|
+
---
|
|
17
|
+
|
|
18
|
+
<header class="ew-header-hide-on-scroll" data-testid="header-hide-on-scroll">
|
|
19
|
+
<div class="ew-header-hide-on-scroll__inner">
|
|
20
|
+
<a href={currentLang === 'de' ? '/' : `/${currentLang}/`} class="ew-header-hide-on-scroll__brand">
|
|
21
|
+
{logoImage ? <Media image={logoImage} class="ew-header-hide-on-scroll__logo" /> : siteName}
|
|
22
|
+
</a>
|
|
23
|
+
|
|
24
|
+
<button
|
|
25
|
+
type="button"
|
|
26
|
+
class="ew-header-hide-on-scroll__menu-btn"
|
|
27
|
+
aria-label={menuLabel}
|
|
28
|
+
aria-expanded="false"
|
|
29
|
+
aria-controls={navId}
|
|
30
|
+
data-testid="mobile-menu-toggle"
|
|
31
|
+
>
|
|
32
|
+
<svg class="ew-header-hide-on-scroll__menu-icon ew-header-hide-on-scroll__menu-icon--open" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
|
|
33
|
+
<line x1="3" y1="6" x2="21" y2="6"></line>
|
|
34
|
+
<line x1="3" y1="12" x2="21" y2="12"></line>
|
|
35
|
+
<line x1="3" y1="18" x2="21" y2="18"></line>
|
|
36
|
+
</svg>
|
|
37
|
+
<svg class="ew-header-hide-on-scroll__menu-icon ew-header-hide-on-scroll__menu-icon--close" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" aria-hidden="true">
|
|
38
|
+
<line x1="18" y1="6" x2="6" y2="18"></line>
|
|
39
|
+
<line x1="6" y1="6" x2="18" y2="18"></line>
|
|
40
|
+
</svg>
|
|
41
|
+
</button>
|
|
42
|
+
|
|
43
|
+
<nav id={navId} class="ew-header-hide-on-scroll__nav" aria-label={labels.mainNavigation}>
|
|
44
|
+
<ul class="ew-header-hide-on-scroll__links">
|
|
45
|
+
{navItems.map((item) => (
|
|
46
|
+
<li>
|
|
47
|
+
<a href={item.href} class:list={['ew-header-hide-on-scroll__link', { 'ew-header-hide-on-scroll__link--active': pathname === item.href }]}>
|
|
48
|
+
{item.label}
|
|
49
|
+
</a>
|
|
50
|
+
</li>
|
|
51
|
+
))}
|
|
52
|
+
</ul>
|
|
53
|
+
<div class="ew-header-hide-on-scroll__actions">
|
|
54
|
+
<slot name="actions">
|
|
55
|
+
<ThemeToggle lang={lang} labels={labelOverrides} />
|
|
56
|
+
{showLanguageSwitch && <LanguageSwitch currentLang={currentLang} pathname={pathname} alternateHref={alternateHref} lang={lang} labels={labelOverrides} />}
|
|
57
|
+
</slot>
|
|
58
|
+
</div>
|
|
59
|
+
</nav>
|
|
60
|
+
</div>
|
|
61
|
+
</header>
|
|
62
|
+
|
|
63
|
+
<style>
|
|
64
|
+
.ew-header-hide-on-scroll {
|
|
65
|
+
position: fixed;
|
|
66
|
+
top: 0;
|
|
67
|
+
left: 0;
|
|
68
|
+
right: 0;
|
|
69
|
+
z-index: 100;
|
|
70
|
+
transition: transform 0.3s ease;
|
|
71
|
+
background: var(--ew-surface);
|
|
72
|
+
border-bottom: 1px solid var(--ew-border);
|
|
73
|
+
}
|
|
74
|
+
.ew-header-hide-on-scroll--hidden {
|
|
75
|
+
transform: translateY(-100%);
|
|
76
|
+
}
|
|
77
|
+
.ew-header-hide-on-scroll__inner {
|
|
78
|
+
display: flex;
|
|
79
|
+
align-items: center;
|
|
80
|
+
justify-content: space-between;
|
|
81
|
+
max-width: 72rem;
|
|
82
|
+
margin: 0 auto;
|
|
83
|
+
padding: var(--ew-space-3) var(--ew-space-5);
|
|
84
|
+
}
|
|
85
|
+
.ew-header-hide-on-scroll__brand {
|
|
86
|
+
font-family: var(--ew-font-sans);
|
|
87
|
+
font-size: var(--ew-text-lg);
|
|
88
|
+
font-weight: 700;
|
|
89
|
+
color: var(--ew-on-surface);
|
|
90
|
+
text-decoration: none;
|
|
91
|
+
letter-spacing: -0.01em;
|
|
92
|
+
}
|
|
93
|
+
.ew-header-hide-on-scroll__brand:hover {
|
|
94
|
+
color: var(--ew-primary);
|
|
95
|
+
}
|
|
96
|
+
.ew-header-hide-on-scroll__logo {
|
|
97
|
+
height: 1.5rem;
|
|
98
|
+
width: auto;
|
|
99
|
+
display: block;
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
.ew-header-hide-on-scroll__menu-btn {
|
|
103
|
+
display: none;
|
|
104
|
+
background: transparent;
|
|
105
|
+
border: none;
|
|
106
|
+
color: var(--ew-on-surface);
|
|
107
|
+
cursor: pointer;
|
|
108
|
+
padding: var(--ew-space-1);
|
|
109
|
+
}
|
|
110
|
+
.ew-header-hide-on-scroll__menu-btn:focus-visible {
|
|
111
|
+
outline: 2px solid var(--ew-primary);
|
|
112
|
+
outline-offset: 2px;
|
|
113
|
+
}
|
|
114
|
+
.ew-header-hide-on-scroll__menu-icon--close { display: none; }
|
|
115
|
+
|
|
116
|
+
.ew-header-hide-on-scroll__nav {
|
|
117
|
+
display: flex;
|
|
118
|
+
align-items: center;
|
|
119
|
+
gap: var(--ew-space-5);
|
|
120
|
+
}
|
|
121
|
+
.ew-header-hide-on-scroll__links {
|
|
122
|
+
display: flex;
|
|
123
|
+
list-style: none;
|
|
124
|
+
margin: 0;
|
|
125
|
+
padding: 0;
|
|
126
|
+
gap: var(--ew-space-1);
|
|
127
|
+
}
|
|
128
|
+
.ew-header-hide-on-scroll__link {
|
|
129
|
+
display: block;
|
|
130
|
+
padding: var(--ew-space-2) var(--ew-space-3);
|
|
131
|
+
border-radius: var(--ew-radius-md);
|
|
132
|
+
color: var(--ew-muted);
|
|
133
|
+
font-family: var(--ew-font-sans);
|
|
134
|
+
font-size: var(--ew-text-sm);
|
|
135
|
+
font-weight: 500;
|
|
136
|
+
text-decoration: none;
|
|
137
|
+
}
|
|
138
|
+
.ew-header-hide-on-scroll__link:hover {
|
|
139
|
+
color: var(--ew-on-surface);
|
|
140
|
+
background: var(--ew-surface-muted);
|
|
141
|
+
}
|
|
142
|
+
.ew-header-hide-on-scroll__link--active {
|
|
143
|
+
color: var(--ew-on-surface);
|
|
144
|
+
background: var(--ew-surface-muted);
|
|
145
|
+
}
|
|
146
|
+
.ew-header-hide-on-scroll__actions {
|
|
147
|
+
display: flex;
|
|
148
|
+
align-items: center;
|
|
149
|
+
gap: var(--ew-space-2);
|
|
150
|
+
border-left: 1px solid var(--ew-border);
|
|
151
|
+
padding-left: var(--ew-space-3);
|
|
152
|
+
margin-left: var(--ew-space-1);
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
@media (max-width: 768px) {
|
|
156
|
+
.ew-header-hide-on-scroll__menu-btn {
|
|
157
|
+
display: flex;
|
|
158
|
+
}
|
|
159
|
+
.ew-header-hide-on-scroll__nav {
|
|
160
|
+
display: none;
|
|
161
|
+
position: absolute;
|
|
162
|
+
top: 100%;
|
|
163
|
+
left: 0;
|
|
164
|
+
right: 0;
|
|
165
|
+
flex-direction: column;
|
|
166
|
+
background: var(--ew-surface);
|
|
167
|
+
border-bottom: 1px solid var(--ew-border);
|
|
168
|
+
padding: var(--ew-space-4) var(--ew-space-5);
|
|
169
|
+
gap: var(--ew-space-4);
|
|
170
|
+
}
|
|
171
|
+
.ew-header-hide-on-scroll__nav[data-open] {
|
|
172
|
+
display: flex;
|
|
173
|
+
}
|
|
174
|
+
.ew-header-hide-on-scroll__links {
|
|
175
|
+
flex-direction: column;
|
|
176
|
+
gap: var(--ew-space-1);
|
|
177
|
+
}
|
|
178
|
+
.ew-header-hide-on-scroll__actions {
|
|
179
|
+
border-left: none;
|
|
180
|
+
padding-left: 0;
|
|
181
|
+
margin-left: 0;
|
|
182
|
+
padding-top: var(--ew-space-3);
|
|
183
|
+
border-top: 1px solid var(--ew-border);
|
|
184
|
+
}
|
|
185
|
+
.ew-header-hide-on-scroll__menu-btn[aria-expanded="true"] .ew-header-hide-on-scroll__menu-icon--open { display: none; }
|
|
186
|
+
.ew-header-hide-on-scroll__menu-btn[aria-expanded="true"] .ew-header-hide-on-scroll__menu-icon--close { display: block; }
|
|
187
|
+
}
|
|
188
|
+
</style>
|
|
189
|
+
|
|
190
|
+
<script>
|
|
191
|
+
function initHeader(headerEl: Element) {
|
|
192
|
+
const applyPadding = () => {
|
|
193
|
+
document.body.style.paddingTop = `${headerEl.getBoundingClientRect().height}px`;
|
|
194
|
+
};
|
|
195
|
+
applyPadding();
|
|
196
|
+
|
|
197
|
+
let lastScrollY = window.scrollY;
|
|
198
|
+
let ticking = false;
|
|
199
|
+
|
|
200
|
+
const handleScroll = () => {
|
|
201
|
+
if (!ticking) {
|
|
202
|
+
window.requestAnimationFrame(() => {
|
|
203
|
+
const currentScrollY = window.scrollY;
|
|
204
|
+
if (currentScrollY > lastScrollY && currentScrollY > 80) {
|
|
205
|
+
headerEl.classList.add('ew-header-hide-on-scroll--hidden');
|
|
206
|
+
} else {
|
|
207
|
+
headerEl.classList.remove('ew-header-hide-on-scroll--hidden');
|
|
208
|
+
}
|
|
209
|
+
lastScrollY = currentScrollY;
|
|
210
|
+
ticking = false;
|
|
211
|
+
});
|
|
212
|
+
ticking = true;
|
|
213
|
+
}
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
window.addEventListener('scroll', handleScroll, { passive: true });
|
|
217
|
+
window.addEventListener('resize', applyPadding);
|
|
218
|
+
|
|
219
|
+
const resizeObserver = 'ResizeObserver' in window ? new ResizeObserver(applyPadding) : null;
|
|
220
|
+
resizeObserver?.observe(headerEl);
|
|
221
|
+
|
|
222
|
+
const btn = headerEl.querySelector('.ew-header-hide-on-scroll__menu-btn') as HTMLButtonElement | null;
|
|
223
|
+
const nav = headerEl.querySelector('.ew-header-hide-on-scroll__nav') as HTMLElement | null;
|
|
224
|
+
if (btn && nav) {
|
|
225
|
+
btn.addEventListener('click', () => {
|
|
226
|
+
const isOpen = btn.getAttribute('aria-expanded') === 'true';
|
|
227
|
+
btn.setAttribute('aria-expanded', String(!isOpen));
|
|
228
|
+
if (isOpen) nav.removeAttribute('data-open');
|
|
229
|
+
else nav.setAttribute('data-open', '');
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
}
|
|
233
|
+
document.querySelectorAll('.ew-header-hide-on-scroll').forEach(initHeader);
|
|
234
|
+
</script>
|
|
@@ -1,82 +1,82 @@
|
|
|
1
|
-
---
|
|
2
|
-
/**
|
|
3
|
-
* LanguageSwitch - links to the alternate locale version of the current page.
|
|
4
|
-
* Convention: default locale (e.g. "de") lives at `/`, non-default (e.g. "en") at `/en/.`.
|
|
5
|
-
* With `alternates`, it renders one link per entry instead of deriving a single one.
|
|
6
|
-
*/
|
|
7
|
-
import type { LanguageSwitchProps } from '../contracts/props.js';
|
|
8
|
-
import { ambientTrailingSlash, toServedPath } from '../i18n/index.js';
|
|
9
|
-
import { resolveLabels } from './labels.js';
|
|
10
|
-
|
|
11
|
-
export type Props = LanguageSwitchProps;
|
|
12
|
-
|
|
13
|
-
const { lang = 'en', labels: labelOverrides } = Astro.props;
|
|
14
|
-
const labels = resolveLabels(lang, labelOverrides);
|
|
15
|
-
const { currentLang, pathname, defaultLocale = 'de', alternateHref: explicitHref, ariaLabel, alternates } = Astro.props;
|
|
16
|
-
|
|
17
|
-
const isDefault = currentLang === defaultLocale;
|
|
18
|
-
const alternateLang = isDefault ? 'en' : defaultLocale;
|
|
19
|
-
const label = alternateLang.toUpperCase();
|
|
20
|
-
|
|
21
|
-
function deriveAlternateHref(): string {
|
|
22
|
-
if (isDefault) {
|
|
23
|
-
return `/en${pathname === '/' ? '/' : pathname}`;
|
|
24
|
-
}
|
|
25
|
-
const stripped = pathname.replace(/^\/en\/?/, '/');
|
|
26
|
-
return stripped || '/';
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
// Render in the form the site serves, so switching language is a direct hit
|
|
30
|
-
// rather than a redirect. Also normalises any alternateHref a page passes in.
|
|
31
|
-
const trailingSlash = ambientTrailingSlash();
|
|
32
|
-
const links = alternates
|
|
33
|
-
? alternates.map((alternate) => ({
|
|
34
|
-
href: toServedPath(alternate.href, trailingSlash),
|
|
35
|
-
hreflang: alternate.lang,
|
|
36
|
-
text: alternate.label ?? alternate.lang.toUpperCase(),
|
|
37
|
-
// The accessible name contains a custom visible label (WCAG 2.5.3).
|
|
38
|
-
ariaLabel: labels.switchToLanguage(alternate.label ?? alternate.lang),
|
|
39
|
-
}))
|
|
40
|
-
: [
|
|
41
|
-
{
|
|
42
|
-
href: toServedPath(explicitHref ?? deriveAlternateHref(), trailingSlash),
|
|
43
|
-
hreflang: alternateLang,
|
|
44
|
-
text: label,
|
|
45
|
-
ariaLabel: ariaLabel ?? labels.switchToLanguage(alternateLang),
|
|
46
|
-
},
|
|
47
|
-
];
|
|
48
|
-
---
|
|
49
|
-
|
|
50
|
-
{links.map((link) => (
|
|
51
|
-
<a href={link.href} class="ew-lang-switch" aria-label={link.ariaLabel} hreflang={link.hreflang}>
|
|
52
|
-
{link.text}
|
|
53
|
-
</a>
|
|
54
|
-
))}
|
|
55
|
-
|
|
56
|
-
<style>
|
|
57
|
-
.ew-lang-switch {
|
|
58
|
-
display: inline-flex;
|
|
59
|
-
align-items: center;
|
|
60
|
-
justify-content: center;
|
|
61
|
-
box-sizing: border-box;
|
|
62
|
-
/* Same shared header-control height as ThemeToggle for a consistent utility row. */
|
|
63
|
-
height: 2.25rem;
|
|
64
|
-
min-width: 2.5rem;
|
|
65
|
-
padding: 0 var(--ew-space-2);
|
|
66
|
-
border: 1px solid var(--ew-border);
|
|
67
|
-
border-radius: var(--ew-radius-md);
|
|
68
|
-
color: var(--ew-on-surface);
|
|
69
|
-
font-family: var(--ew-font-sans);
|
|
70
|
-
font-size: var(--ew-text-sm);
|
|
71
|
-
font-weight: 600;
|
|
72
|
-
text-decoration: none;
|
|
73
|
-
letter-spacing: 0.04em;
|
|
74
|
-
}
|
|
75
|
-
.ew-lang-switch:hover {
|
|
76
|
-
background: var(--ew-surface-muted);
|
|
77
|
-
}
|
|
78
|
-
.ew-lang-switch:focus-visible {
|
|
79
|
-
outline: 2px solid var(--ew-primary);
|
|
80
|
-
outline-offset: 2px;
|
|
81
|
-
}
|
|
82
|
-
</style>
|
|
1
|
+
---
|
|
2
|
+
/**
|
|
3
|
+
* LanguageSwitch - links to the alternate locale version of the current page.
|
|
4
|
+
* Convention: default locale (e.g. "de") lives at `/`, non-default (e.g. "en") at `/en/.`.
|
|
5
|
+
* With `alternates`, it renders one link per entry instead of deriving a single one.
|
|
6
|
+
*/
|
|
7
|
+
import type { LanguageSwitchProps } from '../contracts/props.js';
|
|
8
|
+
import { ambientTrailingSlash, toServedPath } from '../i18n/index.js';
|
|
9
|
+
import { resolveLabels } from './labels.js';
|
|
10
|
+
|
|
11
|
+
export type Props = LanguageSwitchProps;
|
|
12
|
+
|
|
13
|
+
const { lang = 'en', labels: labelOverrides } = Astro.props;
|
|
14
|
+
const labels = resolveLabels(lang, labelOverrides);
|
|
15
|
+
const { currentLang, pathname, defaultLocale = 'de', alternateHref: explicitHref, ariaLabel, alternates } = Astro.props;
|
|
16
|
+
|
|
17
|
+
const isDefault = currentLang === defaultLocale;
|
|
18
|
+
const alternateLang = isDefault ? 'en' : defaultLocale;
|
|
19
|
+
const label = alternateLang.toUpperCase();
|
|
20
|
+
|
|
21
|
+
function deriveAlternateHref(): string {
|
|
22
|
+
if (isDefault) {
|
|
23
|
+
return `/en${pathname === '/' ? '/' : pathname}`;
|
|
24
|
+
}
|
|
25
|
+
const stripped = pathname.replace(/^\/en\/?/, '/');
|
|
26
|
+
return stripped || '/';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
// Render in the form the site serves, so switching language is a direct hit
|
|
30
|
+
// rather than a redirect. Also normalises any alternateHref a page passes in.
|
|
31
|
+
const trailingSlash = ambientTrailingSlash();
|
|
32
|
+
const links = alternates
|
|
33
|
+
? alternates.map((alternate) => ({
|
|
34
|
+
href: toServedPath(alternate.href, trailingSlash),
|
|
35
|
+
hreflang: alternate.lang,
|
|
36
|
+
text: alternate.label ?? alternate.lang.toUpperCase(),
|
|
37
|
+
// The accessible name contains a custom visible label (WCAG 2.5.3).
|
|
38
|
+
ariaLabel: labels.switchToLanguage(alternate.label ?? alternate.lang),
|
|
39
|
+
}))
|
|
40
|
+
: [
|
|
41
|
+
{
|
|
42
|
+
href: toServedPath(explicitHref ?? deriveAlternateHref(), trailingSlash),
|
|
43
|
+
hreflang: alternateLang,
|
|
44
|
+
text: label,
|
|
45
|
+
ariaLabel: ariaLabel ?? labels.switchToLanguage(alternateLang),
|
|
46
|
+
},
|
|
47
|
+
];
|
|
48
|
+
---
|
|
49
|
+
|
|
50
|
+
{links.map((link) => (
|
|
51
|
+
<a href={link.href} class="ew-lang-switch" aria-label={link.ariaLabel} hreflang={link.hreflang}>
|
|
52
|
+
{link.text}
|
|
53
|
+
</a>
|
|
54
|
+
))}
|
|
55
|
+
|
|
56
|
+
<style>
|
|
57
|
+
.ew-lang-switch {
|
|
58
|
+
display: inline-flex;
|
|
59
|
+
align-items: center;
|
|
60
|
+
justify-content: center;
|
|
61
|
+
box-sizing: border-box;
|
|
62
|
+
/* Same shared header-control height as ThemeToggle for a consistent utility row. */
|
|
63
|
+
height: 2.25rem;
|
|
64
|
+
min-width: 2.5rem;
|
|
65
|
+
padding: 0 var(--ew-space-2);
|
|
66
|
+
border: 1px solid var(--ew-border);
|
|
67
|
+
border-radius: var(--ew-radius-md);
|
|
68
|
+
color: var(--ew-on-surface);
|
|
69
|
+
font-family: var(--ew-font-sans);
|
|
70
|
+
font-size: var(--ew-text-sm);
|
|
71
|
+
font-weight: 600;
|
|
72
|
+
text-decoration: none;
|
|
73
|
+
letter-spacing: 0.04em;
|
|
74
|
+
}
|
|
75
|
+
.ew-lang-switch:hover {
|
|
76
|
+
background: var(--ew-surface-muted);
|
|
77
|
+
}
|
|
78
|
+
.ew-lang-switch:focus-visible {
|
|
79
|
+
outline: 2px solid var(--ew-primary);
|
|
80
|
+
outline-offset: 2px;
|
|
81
|
+
}
|
|
82
|
+
</style>
|