@easy-web/core 1.3.3 → 1.5.0

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.
Files changed (43) hide show
  1. package/LICENSE +21 -0
  2. package/package.json +9 -9
  3. package/src/components/Header.astro +205 -205
  4. package/src/components/HeaderCentered.astro +230 -230
  5. package/src/components/HeaderFlyout.astro +370 -370
  6. package/src/components/HeaderHideOnScroll.astro +234 -234
  7. package/src/components/LanguageSwitch.astro +82 -82
  8. package/src/components/NotFound.astro +115 -115
  9. package/src/components/PageShell.astro +82 -82
  10. package/src/components/SeoHead.astro +106 -106
  11. package/src/components/StructuredData.astro +1 -1
  12. package/src/components/ThemeToggle.astro +84 -84
  13. package/src/components/UniversalMedia.astro +106 -106
  14. package/src/components/__tests__/StructuredData.test.ts +1 -1
  15. package/src/components/__tests__/UniversalMedia.test.ts +65 -65
  16. package/src/contracts/__tests__/jsonld.test.ts +1 -1
  17. package/src/contracts/index.ts +1 -1
  18. package/src/contracts/jsonld.ts +1 -1
  19. package/src/i18n/__tests__/factory.test.ts +54 -54
  20. package/src/i18n/__tests__/localized-paths.test.ts +258 -258
  21. package/src/i18n/__tests__/routing-multi-locale.test.ts +89 -89
  22. package/src/i18n/__tests__/seo.test.ts +140 -140
  23. package/src/i18n/factory.ts +66 -66
  24. package/src/i18n/index.ts +5 -5
  25. package/src/i18n/localized-paths.ts +181 -181
  26. package/src/i18n/seo.ts +131 -131
  27. package/src/markdown/__tests__/__fixtures__/abs-src-assets.md +1 -1
  28. package/src/markdown/__tests__/__fixtures__/external-url.md +1 -1
  29. package/src/markdown/__tests__/__fixtures__/public-slash.md +1 -1
  30. package/src/markdown/__tests__/__fixtures__/rel-double-dot.md +1 -1
  31. package/src/markdown/__tests__/index.test.ts +60 -60
  32. package/src/markdown/index.ts +1 -1
  33. package/src/markdown/plugin.ts +42 -42
  34. package/src/schemas/__tests__/notFound.test.ts +32 -32
  35. package/src/schemas/notFound.ts +33 -33
  36. package/src/seo/__tests__/crawl-policy.test.ts +50 -50
  37. package/src/seo/__tests__/integration.test.ts +195 -195
  38. package/src/seo/__tests__/no-index-resolution.test.ts +53 -53
  39. package/src/seo/__tests__/robots-txt.test.ts +66 -66
  40. package/src/seo/__tests__/sitemap-options.test.ts +400 -400
  41. package/src/seo/crawl-policy.ts +36 -36
  42. package/src/seo/index.ts +254 -254
  43. package/src/seo/routes/robots-txt.ts +36 -36
@@ -1,115 +1,115 @@
1
- ---
2
- /**
3
- * NotFound – shared brand-conform 404 content block.
4
- *
5
- * Slotted body component (no `<html>`/`<head>`/`<body>`): consumers wrap it in
6
- * their own layout. Public by design (never auth-gated per ADR 0010), so no
7
- * `client:*` directives, `<script>` tags, or auth imports.
8
- *
9
- * `heading` / `message` are CMS overrides; when absent, the inline LABELS
10
- * dictionary supplies DE/EN fallback copy (`easy-web-i18n` intentionally does
11
- * not ship a UI-string dictionary — inline LABELS is the source of truth for
12
- * uncustomised sites).
13
- */
14
- import Media from './Media.astro';
15
- import type { NotFoundProps } from '../contracts/props.js';
16
-
17
- export type Props = NotFoundProps;
18
-
19
- const LABELS: Record<
20
- string,
21
- { backHome: string; notFoundHeading: string; notFoundMessage: string; switchLanguage: string }
22
- > = {
23
- de: {
24
- backHome: 'Zur Startseite',
25
- notFoundHeading: 'Seite nicht gefunden',
26
- notFoundMessage: 'Die aufgerufene Seite existiert nicht.',
27
- switchLanguage: 'English',
28
- },
29
- en: {
30
- backHome: 'Home',
31
- notFoundHeading: 'Page not found',
32
- notFoundMessage: 'The requested page does not exist.',
33
- switchLanguage: 'Deutsch',
34
- },
35
- };
36
-
37
- const { currentLang, defaultLocale, rootHref, alternateHref, heading, message, image } = Astro.props;
38
-
39
- const t = LABELS[currentLang] ?? LABELS[defaultLocale] ?? LABELS.en;
40
- const resolvedRootHref = rootHref ?? (currentLang === defaultLocale ? '/' : `/${currentLang}/`);
41
- const resolvedHeading = heading ?? t.notFoundHeading;
42
- const resolvedMessage = message ?? t.notFoundMessage;
43
- ---
44
-
45
- <section class="ew-not-found" data-testid="not-found">
46
- {typeof image === 'string' ? (
47
- image ? <img src={image} alt="" class="ew-not-found__image" loading="lazy" /> : null
48
- ) : image ? (
49
- <Media image={image} class="ew-not-found__image" loading="lazy" />
50
- ) : null}
51
- <h1 class="ew-not-found__heading">{resolvedHeading}</h1>
52
- <p class="ew-not-found__message">{resolvedMessage}</p>
53
- <p class="ew-not-found__actions">
54
- <a href={resolvedRootHref} class="ew-not-found__link">{t.backHome}</a>
55
- </p>
56
- {alternateHref ? (
57
- <p class="ew-not-found__alt">
58
- <a href={alternateHref} class="ew-not-found__alt-link">{t.switchLanguage}</a>
59
- </p>
60
- ) : null}
61
- </section>
62
-
63
- <style>
64
- .ew-not-found {
65
- max-width: 40rem;
66
- margin: var(--ew-space-12) auto;
67
- padding: 0 var(--ew-space-5);
68
- text-align: center;
69
- color: var(--ew-on-surface);
70
- }
71
- .ew-not-found__image {
72
- display: block;
73
- max-width: 12rem;
74
- height: auto;
75
- margin: 0 auto var(--ew-space-5);
76
- }
77
- .ew-not-found__heading {
78
- font-family: var(--ew-font-sans);
79
- font-size: clamp(1.75rem, 4vw, 2.5rem);
80
- color: var(--ew-on-surface);
81
- margin: 0 0 var(--ew-space-3);
82
- letter-spacing: -0.01em;
83
- }
84
- .ew-not-found__message {
85
- color: var(--ew-on-surface);
86
- margin: 0 0 var(--ew-space-5);
87
- }
88
- .ew-not-found__actions {
89
- margin: 0 0 var(--ew-space-3);
90
- }
91
- .ew-not-found__link {
92
- display: inline-block;
93
- padding: var(--ew-space-2) var(--ew-space-5);
94
- background: var(--ew-primary);
95
- color: var(--ew-on-primary);
96
- border-radius: var(--ew-radius-md);
97
- font-weight: 600;
98
- text-decoration: none;
99
- }
100
- .ew-not-found__link:hover {
101
- filter: brightness(0.95);
102
- }
103
- .ew-not-found__link:focus-visible {
104
- outline: 2px solid var(--ew-primary);
105
- outline-offset: 2px;
106
- }
107
- .ew-not-found__alt {
108
- margin: 0;
109
- }
110
- .ew-not-found__alt-link {
111
- color: var(--ew-primary);
112
- text-decoration: underline;
113
- font-size: var(--ew-text-sm);
114
- }
115
- </style>
1
+ ---
2
+ /**
3
+ * NotFound – shared brand-conform 404 content block.
4
+ *
5
+ * Slotted body component (no `<html>`/`<head>`/`<body>`): consumers wrap it in
6
+ * their own layout. Public by design (never auth-gated per ADR 0010), so no
7
+ * `client:*` directives, `<script>` tags, or auth imports.
8
+ *
9
+ * `heading` / `message` are CMS overrides; when absent, the inline LABELS
10
+ * dictionary supplies DE/EN fallback copy (`easy-web-i18n` intentionally does
11
+ * not ship a UI-string dictionary — inline LABELS is the source of truth for
12
+ * uncustomised sites).
13
+ */
14
+ import Media from './Media.astro';
15
+ import type { NotFoundProps } from '../contracts/props.js';
16
+
17
+ export type Props = NotFoundProps;
18
+
19
+ const LABELS: Record<
20
+ string,
21
+ { backHome: string; notFoundHeading: string; notFoundMessage: string; switchLanguage: string }
22
+ > = {
23
+ de: {
24
+ backHome: 'Zur Startseite',
25
+ notFoundHeading: 'Seite nicht gefunden',
26
+ notFoundMessage: 'Die aufgerufene Seite existiert nicht.',
27
+ switchLanguage: 'English',
28
+ },
29
+ en: {
30
+ backHome: 'Home',
31
+ notFoundHeading: 'Page not found',
32
+ notFoundMessage: 'The requested page does not exist.',
33
+ switchLanguage: 'Deutsch',
34
+ },
35
+ };
36
+
37
+ const { currentLang, defaultLocale, rootHref, alternateHref, heading, message, image } = Astro.props;
38
+
39
+ const t = LABELS[currentLang] ?? LABELS[defaultLocale] ?? LABELS.en;
40
+ const resolvedRootHref = rootHref ?? (currentLang === defaultLocale ? '/' : `/${currentLang}/`);
41
+ const resolvedHeading = heading ?? t.notFoundHeading;
42
+ const resolvedMessage = message ?? t.notFoundMessage;
43
+ ---
44
+
45
+ <section class="ew-not-found" data-testid="not-found">
46
+ {typeof image === 'string' ? (
47
+ image ? <img src={image} alt="" class="ew-not-found__image" loading="lazy" /> : null
48
+ ) : image ? (
49
+ <Media image={image} class="ew-not-found__image" loading="lazy" />
50
+ ) : null}
51
+ <h1 class="ew-not-found__heading">{resolvedHeading}</h1>
52
+ <p class="ew-not-found__message">{resolvedMessage}</p>
53
+ <p class="ew-not-found__actions">
54
+ <a href={resolvedRootHref} class="ew-not-found__link">{t.backHome}</a>
55
+ </p>
56
+ {alternateHref ? (
57
+ <p class="ew-not-found__alt">
58
+ <a href={alternateHref} class="ew-not-found__alt-link">{t.switchLanguage}</a>
59
+ </p>
60
+ ) : null}
61
+ </section>
62
+
63
+ <style>
64
+ .ew-not-found {
65
+ max-width: 40rem;
66
+ margin: var(--ew-space-12) auto;
67
+ padding: 0 var(--ew-space-5);
68
+ text-align: center;
69
+ color: var(--ew-on-surface);
70
+ }
71
+ .ew-not-found__image {
72
+ display: block;
73
+ max-width: 12rem;
74
+ height: auto;
75
+ margin: 0 auto var(--ew-space-5);
76
+ }
77
+ .ew-not-found__heading {
78
+ font-family: var(--ew-font-sans);
79
+ font-size: clamp(1.75rem, 4vw, 2.5rem);
80
+ color: var(--ew-on-surface);
81
+ margin: 0 0 var(--ew-space-3);
82
+ letter-spacing: -0.01em;
83
+ }
84
+ .ew-not-found__message {
85
+ color: var(--ew-on-surface);
86
+ margin: 0 0 var(--ew-space-5);
87
+ }
88
+ .ew-not-found__actions {
89
+ margin: 0 0 var(--ew-space-3);
90
+ }
91
+ .ew-not-found__link {
92
+ display: inline-block;
93
+ padding: var(--ew-space-2) var(--ew-space-5);
94
+ background: var(--ew-primary);
95
+ color: var(--ew-on-primary);
96
+ border-radius: var(--ew-radius-md);
97
+ font-weight: 600;
98
+ text-decoration: none;
99
+ }
100
+ .ew-not-found__link:hover {
101
+ filter: brightness(0.95);
102
+ }
103
+ .ew-not-found__link:focus-visible {
104
+ outline: 2px solid var(--ew-primary);
105
+ outline-offset: 2px;
106
+ }
107
+ .ew-not-found__alt {
108
+ margin: 0;
109
+ }
110
+ .ew-not-found__alt-link {
111
+ color: var(--ew-primary);
112
+ text-decoration: underline;
113
+ font-size: var(--ew-text-sm);
114
+ }
115
+ </style>
@@ -1,82 +1,82 @@
1
- ---
2
- /**
3
- * PageShell – document-level landmark scaffold: skip link, <main>, and slots for
4
- * the site header and footer.
5
- *
6
- * Exists because a layout that renders `<Header /> <slot /> <Footer />` produces
7
- * a document with no `<main>` landmark and no way to bypass the navigation. That
8
- * fails WCAG 2.1 success criterion 2.4.1 "Bypass Blocks" (Level A), which is
9
- * satisfied by a skip link, a heading, or a landmark region — and such a layout
10
- * offers none of the three on any route whose content does not open with a
11
- * heading. axe-core reports this as `bypass`, and because that rule carries
12
- * `reviewOnFail`, it surfaces as *incomplete* rather than a violation, so a gate
13
- * asserting `violations.length === 0` stays green while the failure ships.
14
- *
15
- * This component owns the DOM order on purpose: the skip link has to precede the
16
- * header to be the first focusable element, which a layout cannot arrange if the
17
- * header is rendered by the caller before the shell.
18
- *
19
- * Usage:
20
- * <PageShell>
21
- * <Header slot="header" ... />
22
- * <slot />
23
- * <Footer slot="footer" ... />
24
- * </PageShell>
25
- */
26
- import type { PageShellProps } from '../contracts/props.js';
27
- import { resolveLabels } from './labels.js';
28
-
29
- export type Props = PageShellProps;
30
-
31
- const { lang = 'en', labels: labelOverrides } = Astro.props;
32
- const labels = resolveLabels(lang, labelOverrides);
33
- const { mainId = 'main-content', skipLabel = labels.skipToMainContent, class: className } = Astro.props;
34
- ---
35
-
36
- <a class="ew-skip-link" href={`#${mainId}`}>{skipLabel}</a>
37
- <slot name="header" />
38
- <!--
39
- tabindex="-1" makes <main> programmatically focusable so activating the skip
40
- link moves focus as well as scroll position. Without it, some browsers scroll
41
- the viewport but leave focus in the nav, so the next Tab returns to the menu —
42
- the control appears to work while not actually bypassing anything.
43
- -->
44
- <main id={mainId} class:list={['ew-main', className]} tabindex="-1">
45
- <slot />
46
- </main>
47
- <slot name="footer" />
48
-
49
- <style>
50
- /*
51
- Off-screen until focused rather than `display: none` — a hidden element is
52
- removed from the focus order entirely, which would make the skip link
53
- unreachable by the keyboard users it exists for.
54
- */
55
- .ew-skip-link {
56
- position: absolute;
57
- left: -9999px;
58
- top: 0;
59
- z-index: 100;
60
- padding: var(--ew-space-2) var(--ew-space-4);
61
- background: var(--ew-surface);
62
- color: var(--ew-on-surface);
63
- border: 1px solid var(--ew-border);
64
- border-radius: var(--ew-radius-md);
65
- font-family: var(--ew-font-sans);
66
- font-size: var(--ew-text-base);
67
- font-weight: 600;
68
- text-decoration: none;
69
- }
70
- .ew-skip-link:focus-visible,
71
- .ew-skip-link:focus {
72
- left: var(--ew-space-3);
73
- top: var(--ew-space-3);
74
- outline: 2px solid var(--ew-primary);
75
- outline-offset: 2px;
76
- }
77
-
78
- /* The landmark itself is layout-neutral; instances style it via `class`. */
79
- .ew-main:focus {
80
- outline: none;
81
- }
82
- </style>
1
+ ---
2
+ /**
3
+ * PageShell – document-level landmark scaffold: skip link, <main>, and slots for
4
+ * the site header and footer.
5
+ *
6
+ * Exists because a layout that renders `<Header /> <slot /> <Footer />` produces
7
+ * a document with no `<main>` landmark and no way to bypass the navigation. That
8
+ * fails WCAG 2.1 success criterion 2.4.1 "Bypass Blocks" (Level A), which is
9
+ * satisfied by a skip link, a heading, or a landmark region — and such a layout
10
+ * offers none of the three on any route whose content does not open with a
11
+ * heading. axe-core reports this as `bypass`, and because that rule carries
12
+ * `reviewOnFail`, it surfaces as *incomplete* rather than a violation, so a gate
13
+ * asserting `violations.length === 0` stays green while the failure ships.
14
+ *
15
+ * This component owns the DOM order on purpose: the skip link has to precede the
16
+ * header to be the first focusable element, which a layout cannot arrange if the
17
+ * header is rendered by the caller before the shell.
18
+ *
19
+ * Usage:
20
+ * <PageShell>
21
+ * <Header slot="header" ... />
22
+ * <slot />
23
+ * <Footer slot="footer" ... />
24
+ * </PageShell>
25
+ */
26
+ import type { PageShellProps } from '../contracts/props.js';
27
+ import { resolveLabels } from './labels.js';
28
+
29
+ export type Props = PageShellProps;
30
+
31
+ const { lang = 'en', labels: labelOverrides } = Astro.props;
32
+ const labels = resolveLabels(lang, labelOverrides);
33
+ const { mainId = 'main-content', skipLabel = labels.skipToMainContent, class: className } = Astro.props;
34
+ ---
35
+
36
+ <a class="ew-skip-link" href={`#${mainId}`}>{skipLabel}</a>
37
+ <slot name="header" />
38
+ <!--
39
+ tabindex="-1" makes <main> programmatically focusable so activating the skip
40
+ link moves focus as well as scroll position. Without it, some browsers scroll
41
+ the viewport but leave focus in the nav, so the next Tab returns to the menu —
42
+ the control appears to work while not actually bypassing anything.
43
+ -->
44
+ <main id={mainId} class:list={['ew-main', className]} tabindex="-1">
45
+ <slot />
46
+ </main>
47
+ <slot name="footer" />
48
+
49
+ <style>
50
+ /*
51
+ Off-screen until focused rather than `display: none` — a hidden element is
52
+ removed from the focus order entirely, which would make the skip link
53
+ unreachable by the keyboard users it exists for.
54
+ */
55
+ .ew-skip-link {
56
+ position: absolute;
57
+ left: -9999px;
58
+ top: 0;
59
+ z-index: 100;
60
+ padding: var(--ew-space-2) var(--ew-space-4);
61
+ background: var(--ew-surface);
62
+ color: var(--ew-on-surface);
63
+ border: 1px solid var(--ew-border);
64
+ border-radius: var(--ew-radius-md);
65
+ font-family: var(--ew-font-sans);
66
+ font-size: var(--ew-text-base);
67
+ font-weight: 600;
68
+ text-decoration: none;
69
+ }
70
+ .ew-skip-link:focus-visible,
71
+ .ew-skip-link:focus {
72
+ left: var(--ew-space-3);
73
+ top: var(--ew-space-3);
74
+ outline: 2px solid var(--ew-primary);
75
+ outline-offset: 2px;
76
+ }
77
+
78
+ /* The landmark itself is layout-neutral; instances style it via `class`. */
79
+ .ew-main:focus {
80
+ outline: none;
81
+ }
82
+ </style>
@@ -1,109 +1,109 @@
1
- ---
1
+ ---
2
2
  import StructuredData from './StructuredData.astro';
3
- import { toServedPath, type TrailingSlash } from '../i18n/index.js';
4
-
5
- export interface AlternateLink {
6
- hreflang: string;
7
- href: string;
8
- }
9
-
10
- export interface Props {
11
- title: string;
12
- description?: string;
13
- pathname: string;
14
- locale: string;
15
- siteName: string;
16
- ogType?: 'website' | 'article';
17
- ogImage?: string;
18
- themeColor?: string;
19
- manifest?: string;
20
- noIndex?: boolean;
21
- twitterCard?: 'summary' | 'summary_large_image';
22
- twitterSite?: string;
23
- alternates?: AlternateLink[];
3
+ import { toServedPath, type TrailingSlash } from '../i18n/index.js';
4
+
5
+ export interface AlternateLink {
6
+ hreflang: string;
7
+ href: string;
8
+ }
9
+
10
+ export interface Props {
11
+ title: string;
12
+ description?: string;
13
+ pathname: string;
14
+ locale: string;
15
+ siteName: string;
16
+ ogType?: 'website' | 'article';
17
+ ogImage?: string;
18
+ themeColor?: string;
19
+ manifest?: string;
20
+ noIndex?: boolean;
21
+ twitterCard?: 'summary' | 'summary_large_image';
22
+ twitterSite?: string;
23
+ alternates?: AlternateLink[];
24
24
  trailingSlash?: TrailingSlash;
25
- structuredData?: object | object[];
26
- }
27
-
28
- const {
29
- title,
30
- description,
31
- pathname,
32
- locale,
33
- siteName,
34
- ogType = 'website',
35
- ogImage,
36
- themeColor,
37
- manifest,
38
- noIndex,
39
- twitterCard = 'summary',
40
- twitterSite,
41
- alternates = [],
25
+ structuredData?: object | object[];
26
+ }
27
+
28
+ const {
29
+ title,
30
+ description,
31
+ pathname,
32
+ locale,
33
+ siteName,
34
+ ogType = 'website',
35
+ ogImage,
36
+ themeColor,
37
+ manifest,
38
+ noIndex,
39
+ twitterCard = 'summary',
40
+ twitterSite,
41
+ alternates = [],
42
42
  trailingSlash,
43
- structuredData,
44
- } = Astro.props;
45
-
46
- const site = Astro.site;
47
- if (!site) {
48
- throw new Error(
49
- '@easy-web/seo: <SeoHead> requires astro.config.mjs to set `site` (a full https:// URL).'
50
- );
51
- }
52
-
53
- // Callers hand-write `pathname` in mixed conventions, so the canonical is
54
- // normalised to the form the site actually serves. It must match the sitemap
55
- // <loc> and the self-referencing hreflang exactly, or Google treats /x and /x/
56
- // as competing duplicates. The style is resolved from Astro's build config by
57
- // the easyWebSeo() integration.
58
- const servedStyle: TrailingSlash =
59
- trailingSlash ?? (process.env.EASY_WEB_SEO_TRAILING_SLASH === 'never' ? 'never' : 'always');
60
- const servedPath = toServedPath(pathname, servedStyle);
61
-
62
- // The built 404 documents answer 200 when requested directly, so without this
63
- // they are ordinary indexable pages whose content happens to say "not found".
64
- // A self-referencing canonical is omitted for the same reason: it would assert
65
- // the page is a canonical destination while the body says the opposite.
66
- const isNotFoundRoute = servedPath.split('/').filter(Boolean).pop() === '404';
67
-
68
- // The crawl policy is resolved once by easyWebSeo() and published to the
69
- // environment, exactly like the trailing-slash style above. Defaulting the prop
70
- // to `false` instead of reading that value meant `easyWebSeo({ noIndex: true })`
71
- // suppressed the sitemap and wrote a disallow-all robots.txt while every page
72
- // still shipped without a robots meta tag — the integration and the document
73
- // disagreeing about the same policy. An explicit prop still wins, so a single
74
- // page can opt out of a site-wide setting.
75
- const policyNoIndex = process.env.EASY_WEB_SEO_NO_INDEX === 'true';
76
- const shouldNoIndex = (noIndex ?? policyNoIndex) || isNotFoundRoute;
77
-
78
- const canonical = new URL(servedPath, site).href;
79
- const absoluteOgImage = ogImage ? new URL(ogImage, site).href : undefined;
80
- // Map locale to OG locale format: 'de' → 'de_DE', 'en' → 'en_US'
81
- const ogLocale = locale === 'en' ? 'en_US' : locale === 'de' ? 'de_DE' : locale.replace('-', '_');
82
- const ogLocaleAlternate = locale === 'en' ? 'de_DE' : 'en_US';
83
- ---
84
- <title>{title}</title>
85
- {description && <meta name="description" content={description} />}
86
- {!isNotFoundRoute && <link rel="canonical" href={canonical} />}
87
- {shouldNoIndex && <meta name="robots" content="noindex, nofollow" />}
88
- {themeColor && <meta name="theme-color" content={themeColor} />}
89
- {manifest && <link rel="manifest" href={manifest} />}
90
- <!-- Open Graph -->
91
- <meta property="og:title" content={title} />
92
- {description && <meta property="og:description" content={description} />}
93
- <meta property="og:url" content={canonical} />
94
- <meta property="og:type" content={ogType} />
95
- <meta property="og:locale" content={ogLocale} />
96
- <meta property="og:locale:alternate" content={ogLocaleAlternate} />
97
- <meta property="og:site_name" content={siteName} />
98
- {absoluteOgImage && <meta property="og:image" content={absoluteOgImage} />}
99
- <!-- Twitter Cards -->
100
- <meta name="twitter:card" content={twitterCard} />
101
- <meta name="twitter:title" content={title} />
102
- {description && <meta name="twitter:description" content={description} />}
103
- {absoluteOgImage && <meta name="twitter:image" content={absoluteOgImage} />}
104
- {twitterSite && <meta name="twitter:site" content={twitterSite} />}
105
- <!-- hreflang alternates -->
106
- {alternates.map((link) => (
107
- <link rel="alternate" hreflang={link.hreflang} href={link.href} />
108
- ))}
109
- {structuredData && <StructuredData data={structuredData} />}
43
+ structuredData,
44
+ } = Astro.props;
45
+
46
+ const site = Astro.site;
47
+ if (!site) {
48
+ throw new Error(
49
+ '@easy-web/seo: <SeoHead> requires astro.config.mjs to set `site` (a full https:// URL).'
50
+ );
51
+ }
52
+
53
+ // Callers hand-write `pathname` in mixed conventions, so the canonical is
54
+ // normalised to the form the site actually serves. It must match the sitemap
55
+ // <loc> and the self-referencing hreflang exactly, or Google treats /x and /x/
56
+ // as competing duplicates. The style is resolved from Astro's build config by
57
+ // the easyWebSeo() integration.
58
+ const servedStyle: TrailingSlash =
59
+ trailingSlash ?? (process.env.EASY_WEB_SEO_TRAILING_SLASH === 'never' ? 'never' : 'always');
60
+ const servedPath = toServedPath(pathname, servedStyle);
61
+
62
+ // The built 404 documents answer 200 when requested directly, so without this
63
+ // they are ordinary indexable pages whose content happens to say "not found".
64
+ // A self-referencing canonical is omitted for the same reason: it would assert
65
+ // the page is a canonical destination while the body says the opposite.
66
+ const isNotFoundRoute = servedPath.split('/').filter(Boolean).pop() === '404';
67
+
68
+ // The crawl policy is resolved once by easyWebSeo() and published to the
69
+ // environment, exactly like the trailing-slash style above. Defaulting the prop
70
+ // to `false` instead of reading that value meant `easyWebSeo({ noIndex: true })`
71
+ // suppressed the sitemap and wrote a disallow-all robots.txt while every page
72
+ // still shipped without a robots meta tag — the integration and the document
73
+ // disagreeing about the same policy. An explicit prop still wins, so a single
74
+ // page can opt out of a site-wide setting.
75
+ const policyNoIndex = process.env.EASY_WEB_SEO_NO_INDEX === 'true';
76
+ const shouldNoIndex = (noIndex ?? policyNoIndex) || isNotFoundRoute;
77
+
78
+ const canonical = new URL(servedPath, site).href;
79
+ const absoluteOgImage = ogImage ? new URL(ogImage, site).href : undefined;
80
+ // Map locale to OG locale format: 'de' → 'de_DE', 'en' → 'en_US'
81
+ const ogLocale = locale === 'en' ? 'en_US' : locale === 'de' ? 'de_DE' : locale.replace('-', '_');
82
+ const ogLocaleAlternate = locale === 'en' ? 'de_DE' : 'en_US';
83
+ ---
84
+ <title>{title}</title>
85
+ {description && <meta name="description" content={description} />}
86
+ {!isNotFoundRoute && <link rel="canonical" href={canonical} />}
87
+ {shouldNoIndex && <meta name="robots" content="noindex, nofollow" />}
88
+ {themeColor && <meta name="theme-color" content={themeColor} />}
89
+ {manifest && <link rel="manifest" href={manifest} />}
90
+ <!-- Open Graph -->
91
+ <meta property="og:title" content={title} />
92
+ {description && <meta property="og:description" content={description} />}
93
+ <meta property="og:url" content={canonical} />
94
+ <meta property="og:type" content={ogType} />
95
+ <meta property="og:locale" content={ogLocale} />
96
+ <meta property="og:locale:alternate" content={ogLocaleAlternate} />
97
+ <meta property="og:site_name" content={siteName} />
98
+ {absoluteOgImage && <meta property="og:image" content={absoluteOgImage} />}
99
+ <!-- Twitter Cards -->
100
+ <meta name="twitter:card" content={twitterCard} />
101
+ <meta name="twitter:title" content={title} />
102
+ {description && <meta name="twitter:description" content={description} />}
103
+ {absoluteOgImage && <meta name="twitter:image" content={absoluteOgImage} />}
104
+ {twitterSite && <meta name="twitter:site" content={twitterSite} />}
105
+ <!-- hreflang alternates -->
106
+ {alternates.map((link) => (
107
+ <link rel="alternate" hreflang={link.hreflang} href={link.href} />
108
+ ))}
109
+ {structuredData && <StructuredData data={structuredData} />}
@@ -5,4 +5,4 @@ export interface Props {
5
5
 
6
6
  const { data } = Astro.props;
7
7
  ---
8
- <script type="application/ld+json" set:html={JSON.stringify(data).replace(/</g, '\\u003c')} />
8
+ <script type="application/ld+json" set:html={JSON.stringify(data).replace(/</g, '\\u003c')} />