@easy-web/content-blocks 1.2.1 → 1.2.2

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@easy-web/content-blocks",
3
- "version": "1.2.1",
3
+ "version": "1.2.2",
4
4
  "type": "module",
5
5
  "description": "Reusable Astro content-block components for the easy-web ecosystem.",
6
6
  "exports": {
@@ -23,8 +23,8 @@
23
23
  "zod": ">=4.0.0"
24
24
  },
25
25
  "dependencies": {
26
- "@easy-web/i18n": "1.2.1",
27
- "@easy-web/theme-core": "1.2.1"
26
+ "@easy-web/i18n": "1.2.2",
27
+ "@easy-web/theme-core": "1.2.2"
28
28
  },
29
29
  "devDependencies": {
30
30
  "astro": "^6.4.0",
@@ -1,8 +1,10 @@
1
1
  ---
2
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/…`.
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
5
  */
6
+ import { ambientTrailingSlash, toServedPath } from '@easy-web/i18n';
7
+
6
8
  interface Props {
7
9
  /** Current page language, e.g. "de" or "en". */
8
10
  currentLang: string;
@@ -10,7 +12,7 @@ interface Props {
10
12
  pathname: string;
11
13
  /** The default locale that uses bare paths (no prefix). Defaults to "de". */
12
14
  defaultLocale?: string;
13
- /** Explicit alternate URL for translated slugs (e.g. /en/privacy/ for /datenschutz/). Bypasses automatic derivation. */
15
+ /** Explicit alternate URL for translated slugs (e.g. /en/privacy for /datenschutz). Bypasses automatic derivation. */
14
16
  alternateHref?: string;
15
17
  /** Accessible label override. */
16
18
  ariaLabel?: string;
@@ -30,7 +32,9 @@ function deriveAlternateHref(): string {
30
32
  return stripped || '/';
31
33
  }
32
34
 
33
- const resolvedHref = explicitHref ?? deriveAlternateHref();
35
+ // Render in the form the site serves, so switching language is a direct hit
36
+ // rather than a redirect. Also normalises any alternateHref a page passes in.
37
+ const resolvedHref = toServedPath(explicitHref ?? deriveAlternateHref(), ambientTrailingSlash());
34
38
  const resolvedAriaLabel = ariaLabel ?? `Switch to ${alternateLang}`;
35
39
  ---
36
40