@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,60 +1,60 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { unified } from 'unified';
3
- import type { Root, Image } from 'mdast';
4
- import { visit } from 'unist-util-visit';
5
- import { VFile } from 'vfile';
6
- import easyWebMarkdown from '../index.js';
7
-
8
- function getImageUrls(tree: Root): string[] {
9
- const urls: string[] = [];
10
- visit(tree, 'image', (node: Image) => {
11
- urls.push(node.url);
12
- });
13
- return urls;
14
- }
15
-
16
- function makeImageTree(url: string): Root {
17
- return {
18
- type: 'root',
19
- children: [
20
- {
21
- type: 'paragraph',
22
- children: [{ type: 'image', url, alt: 'test', title: null }],
23
- },
24
- ],
25
- };
26
- }
27
-
28
- describe('easyWebMarkdown remark plugin', () => {
29
- it('rewrites /src/assets/ URL to relative path from md file', () => {
30
- const tree = makeImageTree('/src/assets/images/foo.png');
31
- const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
32
- const processor = unified().use(easyWebMarkdown);
33
- processor.runSync(tree, file);
34
- expect(getImageUrls(tree)).toEqual(['../../../assets/images/foo.png']);
35
- });
36
-
37
- it('passes through relative ../../ URL unchanged', () => {
38
- const tree = makeImageTree('../../assets/foo.png');
39
- const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
40
- const processor = unified().use(easyWebMarkdown);
41
- processor.runSync(tree, file);
42
- expect(getImageUrls(tree)).toEqual(['../../assets/foo.png']);
43
- });
44
-
45
- it('passes through external URL unchanged', () => {
46
- const tree = makeImageTree('https://example.com/foo.png');
47
- const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
48
- const processor = unified().use(easyWebMarkdown);
49
- processor.runSync(tree, file);
50
- expect(getImageUrls(tree)).toEqual(['https://example.com/foo.png']);
51
- });
52
-
53
- it('passes through /uploads/ public-folder URL unchanged', () => {
54
- const tree = makeImageTree('/uploads/foo.png');
55
- const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
56
- const processor = unified().use(easyWebMarkdown);
57
- processor.runSync(tree, file);
58
- expect(getImageUrls(tree)).toEqual(['/uploads/foo.png']);
59
- });
60
- });
1
+ import { describe, it, expect } from 'vitest';
2
+ import { unified } from 'unified';
3
+ import type { Root, Image } from 'mdast';
4
+ import { visit } from 'unist-util-visit';
5
+ import { VFile } from 'vfile';
6
+ import easyWebMarkdown from '../index.js';
7
+
8
+ function getImageUrls(tree: Root): string[] {
9
+ const urls: string[] = [];
10
+ visit(tree, 'image', (node: Image) => {
11
+ urls.push(node.url);
12
+ });
13
+ return urls;
14
+ }
15
+
16
+ function makeImageTree(url: string): Root {
17
+ return {
18
+ type: 'root',
19
+ children: [
20
+ {
21
+ type: 'paragraph',
22
+ children: [{ type: 'image', url, alt: 'test', title: null }],
23
+ },
24
+ ],
25
+ };
26
+ }
27
+
28
+ describe('easyWebMarkdown remark plugin', () => {
29
+ it('rewrites /src/assets/ URL to relative path from md file', () => {
30
+ const tree = makeImageTree('/src/assets/images/foo.png');
31
+ const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
32
+ const processor = unified().use(easyWebMarkdown);
33
+ processor.runSync(tree, file);
34
+ expect(getImageUrls(tree)).toEqual(['../../../assets/images/foo.png']);
35
+ });
36
+
37
+ it('passes through relative ../../ URL unchanged', () => {
38
+ const tree = makeImageTree('../../assets/foo.png');
39
+ const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
40
+ const processor = unified().use(easyWebMarkdown);
41
+ processor.runSync(tree, file);
42
+ expect(getImageUrls(tree)).toEqual(['../../assets/foo.png']);
43
+ });
44
+
45
+ it('passes through external URL unchanged', () => {
46
+ const tree = makeImageTree('https://example.com/foo.png');
47
+ const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
48
+ const processor = unified().use(easyWebMarkdown);
49
+ processor.runSync(tree, file);
50
+ expect(getImageUrls(tree)).toEqual(['https://example.com/foo.png']);
51
+ });
52
+
53
+ it('passes through /uploads/ public-folder URL unchanged', () => {
54
+ const tree = makeImageTree('/uploads/foo.png');
55
+ const file = new VFile({ path: '/project/src/content/pages/de/page.md' });
56
+ const processor = unified().use(easyWebMarkdown);
57
+ processor.runSync(tree, file);
58
+ expect(getImageUrls(tree)).toEqual(['/uploads/foo.png']);
59
+ });
60
+ });
@@ -1 +1 @@
1
- export { default } from './plugin.js';
1
+ export { default } from './plugin.js';
@@ -1,42 +1,42 @@
1
- import { visit } from 'unist-util-visit';
2
- import type { Plugin } from 'unified';
3
- import type { Root, Image } from 'mdast';
4
- import { posix as path } from 'node:path';
5
-
6
- /**
7
- * Remark plugin for easy-web.
8
- * Rewrites markdown image URLs starting with `/src/assets/` to relative paths
9
- * from the markdown file's location — a format Astro's built-in image resolver accepts.
10
- *
11
- * URLs NOT starting with `/src/assets/` are passed through unchanged.
12
- */
13
- const easyWebMarkdown: Plugin<[], Root> = () => {
14
- return (tree, file) => {
15
- const rawPath = (file.history?.[0] ?? file.path) as string | undefined;
16
- if (!rawPath) return;
17
-
18
- // Normalise to forward slashes (Astro always provides POSIX paths)
19
- const filePath = rawPath.replace(/\\/g, '/');
20
-
21
- visit(tree, 'image', (node: Image) => {
22
- if (!node.url.startsWith('/src/assets/')) return;
23
-
24
- // Locate the /src/ boundary in the md file's path
25
- const srcBoundary = filePath.lastIndexOf('/src/');
26
- if (srcBoundary === -1) return;
27
-
28
- const projectRoot = filePath.substring(0, srcBoundary);
29
- const fileDir = path.dirname(filePath);
30
-
31
- // Asset absolute path: projectRoot + /src/assets/...
32
- const assetAbsolute = projectRoot + node.url;
33
-
34
- // Compute relative path from .md directory to asset
35
- const relativePath = path.relative(fileDir, assetAbsolute);
36
-
37
- node.url = relativePath;
38
- });
39
- };
40
- };
41
-
42
- export default easyWebMarkdown;
1
+ import { visit } from 'unist-util-visit';
2
+ import type { Plugin } from 'unified';
3
+ import type { Root, Image } from 'mdast';
4
+ import { posix as path } from 'node:path';
5
+
6
+ /**
7
+ * Remark plugin for easy-web.
8
+ * Rewrites markdown image URLs starting with `/src/assets/` to relative paths
9
+ * from the markdown file's location — a format Astro's built-in image resolver accepts.
10
+ *
11
+ * URLs NOT starting with `/src/assets/` are passed through unchanged.
12
+ */
13
+ const easyWebMarkdown: Plugin<[], Root> = () => {
14
+ return (tree, file) => {
15
+ const rawPath = (file.history?.[0] ?? file.path) as string | undefined;
16
+ if (!rawPath) return;
17
+
18
+ // Normalise to forward slashes (Astro always provides POSIX paths)
19
+ const filePath = rawPath.replace(/\\/g, '/');
20
+
21
+ visit(tree, 'image', (node: Image) => {
22
+ if (!node.url.startsWith('/src/assets/')) return;
23
+
24
+ // Locate the /src/ boundary in the md file's path
25
+ const srcBoundary = filePath.lastIndexOf('/src/');
26
+ if (srcBoundary === -1) return;
27
+
28
+ const projectRoot = filePath.substring(0, srcBoundary);
29
+ const fileDir = path.dirname(filePath);
30
+
31
+ // Asset absolute path: projectRoot + /src/assets/...
32
+ const assetAbsolute = projectRoot + node.url;
33
+
34
+ // Compute relative path from .md directory to asset
35
+ const relativePath = path.relative(fileDir, assetAbsolute);
36
+
37
+ node.url = relativePath;
38
+ });
39
+ };
40
+ };
41
+
42
+ export default easyWebMarkdown;
@@ -1,32 +1,32 @@
1
- import { describe, it, expect } from 'vitest';
2
- import { notFoundSchema } from '../notFound.js';
3
-
4
- describe('notFoundSchema', () => {
5
- it('parses a multi-locale object with partial fields', () => {
6
- const input = {
7
- de: { heading: 'Seite nicht gefunden', message: 'Existiert nicht.' },
8
- en: { heading: 'Not found' },
9
- };
10
- expect(() => notFoundSchema.parse(input)).not.toThrow();
11
- const result = notFoundSchema.parse(input);
12
- expect(result.de.heading).toBe('Seite nicht gefunden');
13
- expect(result.en.heading).toBe('Not found');
14
- });
15
-
16
- it('parses an empty object (all fields optional)', () => {
17
- expect(() => notFoundSchema.parse({})).not.toThrow();
18
- expect(notFoundSchema.parse({})).toEqual({});
19
- });
20
-
21
- it('parses arbitrary locale keys (open record)', () => {
22
- const input = { de: {}, fr: {}, sq: {} };
23
- expect(() => notFoundSchema.parse(input)).not.toThrow();
24
- const result = notFoundSchema.parse(input);
25
- expect(Object.keys(result)).toEqual(expect.arrayContaining(['de', 'fr', 'sq']));
26
- });
27
-
28
- it('rejects a record where image is not a string', () => {
29
- const input = { de: { image: 42 } };
30
- expect(() => notFoundSchema.parse(input)).toThrow();
31
- });
32
- });
1
+ import { describe, it, expect } from 'vitest';
2
+ import { notFoundSchema } from '../notFound.js';
3
+
4
+ describe('notFoundSchema', () => {
5
+ it('parses a multi-locale object with partial fields', () => {
6
+ const input = {
7
+ de: { heading: 'Seite nicht gefunden', message: 'Existiert nicht.' },
8
+ en: { heading: 'Not found' },
9
+ };
10
+ expect(() => notFoundSchema.parse(input)).not.toThrow();
11
+ const result = notFoundSchema.parse(input);
12
+ expect(result.de.heading).toBe('Seite nicht gefunden');
13
+ expect(result.en.heading).toBe('Not found');
14
+ });
15
+
16
+ it('parses an empty object (all fields optional)', () => {
17
+ expect(() => notFoundSchema.parse({})).not.toThrow();
18
+ expect(notFoundSchema.parse({})).toEqual({});
19
+ });
20
+
21
+ it('parses arbitrary locale keys (open record)', () => {
22
+ const input = { de: {}, fr: {}, sq: {} };
23
+ expect(() => notFoundSchema.parse(input)).not.toThrow();
24
+ const result = notFoundSchema.parse(input);
25
+ expect(Object.keys(result)).toEqual(expect.arrayContaining(['de', 'fr', 'sq']));
26
+ });
27
+
28
+ it('rejects a record where image is not a string', () => {
29
+ const input = { de: { image: 42 } };
30
+ expect(() => notFoundSchema.parse(input)).toThrow();
31
+ });
32
+ });
@@ -1,33 +1,33 @@
1
- /**
2
- * Not-found (404) singleton schema — locale-keyed CMS-editable content.
3
- *
4
- * Each locale key maps to an optional set of fields rendered by the site's
5
- * 404 page. All fields are optional so partial translations are valid; a
6
- * consuming page falls back to defaults when a field is absent.
7
- *
8
- * The record key is an open `z.string()` so any IETF locale tag (e.g. `de`,
9
- * `en`, `fr`, `sq`, `de-AT`) is accepted without schema changes. Do NOT add
10
- * SEO metadata (title, canonical) here — those belong to the page layer.
11
- *
12
- * Usage:
13
- *
14
- * ```ts
15
- * import { notFoundSchema } from '@easy-web/content-blocks/schemas/notFound';
16
- *
17
- * const data = notFoundSchema.parse(await import('../content/not-found.json'));
18
- * ```
19
- *
20
- * @see docs/decisions/0011-content-architecture-strategy.md
21
- * @see docs/decisions/0013-shared-not-found-primitives.md
22
- */
23
- import { z } from 'astro/zod';
24
-
25
- export const localizedNotFoundSchema = z.object({
26
- image: z.string().optional(),
27
- heading: z.string().optional(),
28
- message: z.string().optional(),
29
- });
30
-
31
- export const notFoundSchema = z.record(z.string(), localizedNotFoundSchema);
32
-
33
- export type NotFoundData = z.infer<typeof notFoundSchema>;
1
+ /**
2
+ * Not-found (404) singleton schema — locale-keyed CMS-editable content.
3
+ *
4
+ * Each locale key maps to an optional set of fields rendered by the site's
5
+ * 404 page. All fields are optional so partial translations are valid; a
6
+ * consuming page falls back to defaults when a field is absent.
7
+ *
8
+ * The record key is an open `z.string()` so any IETF locale tag (e.g. `de`,
9
+ * `en`, `fr`, `sq`, `de-AT`) is accepted without schema changes. Do NOT add
10
+ * SEO metadata (title, canonical) here — those belong to the page layer.
11
+ *
12
+ * Usage:
13
+ *
14
+ * ```ts
15
+ * import { notFoundSchema } from '@easy-web/content-blocks/schemas/notFound';
16
+ *
17
+ * const data = notFoundSchema.parse(await import('../content/not-found.json'));
18
+ * ```
19
+ *
20
+ * @see docs/decisions/0011-content-architecture-strategy.md
21
+ * @see docs/decisions/0013-shared-not-found-primitives.md
22
+ */
23
+ import { z } from 'astro/zod';
24
+
25
+ export const localizedNotFoundSchema = z.object({
26
+ image: z.string().optional(),
27
+ heading: z.string().optional(),
28
+ message: z.string().optional(),
29
+ });
30
+
31
+ export const notFoundSchema = z.record(z.string(), localizedNotFoundSchema);
32
+
33
+ export type NotFoundData = z.infer<typeof notFoundSchema>;
@@ -1,50 +1,50 @@
1
- import { describe, it, expect } from 'vitest'
2
- import { createCrawlPolicy, isDisallowedPath } from '../crawl-policy.js'
3
-
4
- describe('createCrawlPolicy', () => {
5
- it('blocks only /admin/ and publishes a sitemap in public mode', () => {
6
- const policy = createCrawlPolicy(false)
7
-
8
- expect(policy.disallow).toEqual(['/admin/'])
9
- expect(policy.allow).toEqual(['/'])
10
- expect(policy.sitemap).toBe(true)
11
- })
12
-
13
- it('blocks everything and publishes no sitemap in noIndex mode', () => {
14
- const policy = createCrawlPolicy(true)
15
-
16
- expect(policy.disallow).toEqual(['/'])
17
- expect(policy.allow).toEqual([])
18
- expect(policy.sitemap).toBe(false)
19
- })
20
- })
21
-
22
- describe('isDisallowedPath', () => {
23
- const publicPolicy = createCrawlPolicy(false)
24
-
25
- it('matches the admin route with and without a trailing slash', () => {
26
- expect(isDisallowedPath('/admin', publicPolicy)).toBe(true)
27
- expect(isDisallowedPath('/admin/', publicPolicy)).toBe(true)
28
- })
29
-
30
- it('matches nested admin routes', () => {
31
- expect(isDisallowedPath('/admin/settings/', publicPolicy)).toBe(true)
32
- })
33
-
34
- it('does not match routes that merely share the admin prefix', () => {
35
- expect(isDisallowedPath('/administration/', publicPolicy)).toBe(false)
36
- expect(isDisallowedPath('/adminfoo', publicPolicy)).toBe(false)
37
- })
38
-
39
- it('leaves ordinary routes crawlable', () => {
40
- expect(isDisallowedPath('/', publicPolicy)).toBe(false)
41
- expect(isDisallowedPath('/datenschutz/', publicPolicy)).toBe(false)
42
- })
43
-
44
- it('blocks every path in noIndex mode', () => {
45
- const policy = createCrawlPolicy(true)
46
-
47
- expect(isDisallowedPath('/', policy)).toBe(true)
48
- expect(isDisallowedPath('/bikes/fatboy/', policy)).toBe(true)
49
- })
50
- })
1
+ import { describe, it, expect } from 'vitest'
2
+ import { createCrawlPolicy, isDisallowedPath } from '../crawl-policy.js'
3
+
4
+ describe('createCrawlPolicy', () => {
5
+ it('blocks only /admin/ and publishes a sitemap in public mode', () => {
6
+ const policy = createCrawlPolicy(false)
7
+
8
+ expect(policy.disallow).toEqual(['/admin/'])
9
+ expect(policy.allow).toEqual(['/'])
10
+ expect(policy.sitemap).toBe(true)
11
+ })
12
+
13
+ it('blocks everything and publishes no sitemap in noIndex mode', () => {
14
+ const policy = createCrawlPolicy(true)
15
+
16
+ expect(policy.disallow).toEqual(['/'])
17
+ expect(policy.allow).toEqual([])
18
+ expect(policy.sitemap).toBe(false)
19
+ })
20
+ })
21
+
22
+ describe('isDisallowedPath', () => {
23
+ const publicPolicy = createCrawlPolicy(false)
24
+
25
+ it('matches the admin route with and without a trailing slash', () => {
26
+ expect(isDisallowedPath('/admin', publicPolicy)).toBe(true)
27
+ expect(isDisallowedPath('/admin/', publicPolicy)).toBe(true)
28
+ })
29
+
30
+ it('matches nested admin routes', () => {
31
+ expect(isDisallowedPath('/admin/settings/', publicPolicy)).toBe(true)
32
+ })
33
+
34
+ it('does not match routes that merely share the admin prefix', () => {
35
+ expect(isDisallowedPath('/administration/', publicPolicy)).toBe(false)
36
+ expect(isDisallowedPath('/adminfoo', publicPolicy)).toBe(false)
37
+ })
38
+
39
+ it('leaves ordinary routes crawlable', () => {
40
+ expect(isDisallowedPath('/', publicPolicy)).toBe(false)
41
+ expect(isDisallowedPath('/datenschutz/', publicPolicy)).toBe(false)
42
+ })
43
+
44
+ it('blocks every path in noIndex mode', () => {
45
+ const policy = createCrawlPolicy(true)
46
+
47
+ expect(isDisallowedPath('/', policy)).toBe(true)
48
+ expect(isDisallowedPath('/bikes/fatboy/', policy)).toBe(true)
49
+ })
50
+ })