@easy-web/core 1.7.1 → 1.9.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 (35) hide show
  1. package/README.md +23 -1
  2. package/dist/contracts/props.d.ts +4 -0
  3. package/dist/contracts/props.d.ts.map +1 -1
  4. package/dist/recipes/content-site.d.ts +75 -0
  5. package/dist/recipes/content-site.d.ts.map +1 -0
  6. package/dist/recipes/content-site.js +198 -0
  7. package/dist/recipes/content-site.js.map +1 -0
  8. package/dist/recipes/index.d.ts +1 -0
  9. package/dist/recipes/index.d.ts.map +1 -1
  10. package/dist/recipes/index.js +1 -0
  11. package/dist/recipes/index.js.map +1 -1
  12. package/dist/recipes/shell-recipe.d.ts +8 -1
  13. package/dist/recipes/shell-recipe.d.ts.map +1 -1
  14. package/dist/recipes/shell-recipe.js +21 -16
  15. package/dist/recipes/shell-recipe.js.map +1 -1
  16. package/package.json +1 -1
  17. package/src/components/Card.astro +2 -2
  18. package/src/components/GalleryLightboxGrid.astro +1 -1
  19. package/src/components/Header.astro +1 -1
  20. package/src/components/HeaderCentered.astro +1 -1
  21. package/src/components/HeaderFlyout.astro +2 -2
  22. package/src/components/HeaderHideOnScroll.astro +1 -1
  23. package/src/components/PageShell.astro +1 -1
  24. package/src/components/SeoHead.astro +22 -4
  25. package/src/components/__tests__/Card.test.ts +16 -0
  26. package/src/contracts/props.ts +4 -0
  27. package/src/recipes/__tests__/content-site.test.ts +66 -0
  28. package/src/recipes/__tests__/shell-recipe.test.ts +3 -1
  29. package/src/recipes/content-site.ts +225 -0
  30. package/src/recipes/index.ts +1 -0
  31. package/src/recipes/shell-recipe.ts +29 -17
  32. package/src/seo/__tests__/__snapshots__/legacy-baseline.test.ts.snap +1 -1
  33. package/src/seo/__tests__/legacy-baseline.test.ts +2 -1
  34. package/src/seo/__tests__/og-locales.test.ts +55 -0
  35. package/src/type-tests/card-props.ts +10 -0
@@ -0,0 +1,55 @@
1
+ import { describe, expect, it } from 'vitest';
2
+ import { experimental_AstroContainer as AstroContainer } from 'astro/container';
3
+ import SeoHead from '../../components/SeoHead.astro';
4
+
5
+ async function render(locale: string, languages?: string[]) {
6
+ const container = await AstroContainer.create({ astroConfig: { site: 'https://example.com' } });
7
+ return container.renderToString(SeoHead, {
8
+ props: {
9
+ title: 'Gallery',
10
+ pathname: '/gallery',
11
+ locale,
12
+ siteName: 'Example',
13
+ noIndex: true,
14
+ ...(languages ? {
15
+ alternates: languages.map(hreflang => ({ hreflang, href: `https://example.com/${hreflang}/` })),
16
+ } : {}),
17
+ },
18
+ });
19
+ }
20
+
21
+ function alternates(html: string) {
22
+ return [...html.matchAll(/<meta property="og:locale:alternate" content="([^"]+)"/g)]
23
+ .map(match => match[1]);
24
+ }
25
+
26
+ describe('SeoHead Open Graph locales', () => {
27
+ it.each([undefined, [], ['de']])('emits no invented alternate for a German-only site (%j)', async languages => {
28
+ const html = await render('de', languages);
29
+ expect(alternates(html)).toEqual([]);
30
+ expect(html).toContain('<meta property="og:locale" content="de_DE"');
31
+ });
32
+
33
+ it.each([
34
+ ['de', ['de', 'en'], ['en_US']],
35
+ ['en', ['de', 'en'], ['de_DE']],
36
+ ['de', ['de', 'de-DE', 'DE_de', 'en', 'en-US', 'EN_us', 'x-default', 'X-DEFAULT'], ['en_US']],
37
+ ['de-AT', ['de-at', 'de', 'de-CH', 'en-GB', 'EN_gb', 'fr-ca'], ['de_DE', 'de_CH', 'en_GB', 'fr_CA']],
38
+ ['zh-Hant-TW', ['zh-hant-tw', 'zh-Hans-CN', 'pt-br', 'es-419'], ['zh_Hans_CN', 'pt_BR', 'es_419']],
39
+ ])('derives alternates for %s from configured links', async (locale, languages, expected) => {
40
+ const html = await render(locale, languages);
41
+ expect(alternates(html)).toEqual(expected);
42
+ // OG filtering must not remove or normalize the actual hreflang links.
43
+ for (const language of languages) {
44
+ expect(html).toContain(`hreflang="${language}" href="https://example.com/${language}/"`);
45
+ }
46
+ expect(html).toContain('rel="canonical" href="https://example.com/gallery/"');
47
+ expect(html).toContain('name="robots" content="noindex, nofollow"');
48
+ });
49
+
50
+ it.each([
51
+ ['en', 'en_US'], ['de', 'de_DE'], ['de-AT', 'de_AT'], ['en-GB', 'en_GB'], ['fr', 'fr'],
52
+ ])('preserves the current locale mapping for %s', async (locale, expected) => {
53
+ expect(await render(locale)).toContain(`<meta property="og:locale" content="${expected}"`);
54
+ });
55
+ });
@@ -12,6 +12,7 @@ const itemCard: CardProps = {
12
12
  item: { title: 'Touring bicycle', href: '/bikes/touring/', image },
13
13
  imageSizes: '(min-width: 1024px) 33vw, 100vw',
14
14
  class: 'featured',
15
+ headingLevel: 'h2',
15
16
  };
16
17
 
17
18
  const itemCardWithoutLink: CardProps = { item: { title: 'Touring bicycle', description: 'Ready for long rides' } };
@@ -21,8 +22,15 @@ const legacyCard: CardProps = {
21
22
  href: '/bikes/touring/',
22
23
  image: '/images/touring.jpg',
23
24
  imageAlt: 'A touring bicycle',
25
+ headingLevel: 'h4',
24
26
  };
25
27
 
28
+ // @ts-expect-error Only heading elements are allowed as card titles.
29
+ const nonHeadingCard: CardProps = { item: { title: 'Gallery' }, headingLevel: 'div' };
30
+
31
+ // @ts-expect-error Heading levels use tag names, not numeric ranks.
32
+ const numericHeadingCard: CardProps = { title: 'Gallery', headingLevel: 2 };
33
+
26
34
  // @ts-expect-error An item image carries its own alt text; the title is no fallback.
27
35
  const itemImageWithoutAlt: CardProps = { item: { title: 'Touring bicycle', image: { src: '/images/touring.jpg' } } };
28
36
 
@@ -56,6 +64,8 @@ const grid: CardGridProps = { class: 'news-grid' };
56
64
  void itemCard;
57
65
  void itemCardWithoutLink;
58
66
  void legacyCard;
67
+ void nonHeadingCard;
68
+ void numericHeadingCard;
59
69
  void itemImageWithoutAlt;
60
70
  void mixedCard;
61
71
  void legacyCardWithSizes;