@brightsideoy/kama 1.0.0-alpha.3 → 1.0.0-alpha.31

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 (111) hide show
  1. package/README.md +25 -7
  2. package/bin/cli.js +539 -359
  3. package/content/definitions/blocks/button.yaml +15 -5
  4. package/content/definitions/blocks/form.yaml +20 -0
  5. package/content/definitions/blocks/image-gallery.yaml +34 -0
  6. package/content/definitions/blocks/node-list.yaml +75 -0
  7. package/content/definitions/blocks/youtube.yaml +8 -0
  8. package/content/definitions/field-sets/access.yaml +14 -0
  9. package/content/definitions/field-sets/page-base.yaml +19 -1
  10. package/content/definitions/forms/.gitkeep +0 -0
  11. package/content/definitions/forms/contact.yaml +38 -0
  12. package/content/definitions/forms/subscription.yaml +26 -0
  13. package/content/definitions/nodes/article.yaml +19 -1
  14. package/content/definitions/taxonomies/categories.yaml +5 -2
  15. package/content/definitions/taxonomies/media-tag.yaml +15 -0
  16. package/content/definitions/taxonomies/tags.yaml +5 -2
  17. package/definitions/editor/default.ts +19 -2
  18. package/dist/assets/AssetEditor-CAvQEsBT.js +1 -0
  19. package/dist/assets/AssetEditor-CQtKSOjX.css +1 -0
  20. package/dist/assets/CmsAccordion-91I5Rx5D.css +1 -0
  21. package/dist/assets/CmsAccordion-BgdaB8QZ.js +1 -0
  22. package/dist/assets/CmsBadge-BT2jTJUu.js +1 -0
  23. package/dist/assets/CmsBadge-Ip5hXw8G.css +1 -0
  24. package/dist/assets/CmsButton-DATGQeoC.css +1 -0
  25. package/dist/assets/CmsButton-DnhPsHXA.js +1 -0
  26. package/dist/assets/CmsFieldTaxonomy-CNY3-MbD.js +1 -0
  27. package/dist/assets/CmsFieldTaxonomy-CVlKL-l2.css +1 -0
  28. package/dist/assets/CmsHelp-BO_vWABq.css +1 -0
  29. package/dist/assets/CmsHelp-DtPeURCv.js +1 -0
  30. package/dist/assets/CmsImagePreview-BhM7S_v8.js +1 -0
  31. package/dist/assets/CmsImagePreview-CujwG8r_.css +1 -0
  32. package/dist/assets/CmsPublisher-BcrQAr1m.css +1 -0
  33. package/dist/assets/CmsPublisher-DiQhfPID.js +3 -0
  34. package/dist/assets/CmsUserCenter-CAaiCweN.js +1 -0
  35. package/dist/assets/CmsUserCenter-D3OZYHD0.css +1 -0
  36. package/dist/assets/EditorSplitPreview-BfGni85I.js +1 -0
  37. package/dist/assets/EditorSplitPreview-CMoTjLW5.css +1 -0
  38. package/dist/assets/FormsWorkspace-CGs6eUjz.css +1 -0
  39. package/dist/assets/FormsWorkspace-CUK-y2dR.js +2 -0
  40. package/dist/assets/NodeContextMenu-C5RTK0sr.js +1 -0
  41. package/dist/assets/NodeContextMenu-Cj-2TvQC.css +1 -0
  42. package/dist/assets/NodeEditor-C2meZIvc.css +1 -0
  43. package/dist/assets/NodeEditor-C5VQu52a.js +161 -0
  44. package/dist/assets/SettingsDashboard-XBOgYUn3.css +1 -0
  45. package/dist/assets/SettingsDashboard-gzHzxsIc.js +1 -0
  46. package/dist/assets/StatusPill-Dlm6uvGe.css +1 -0
  47. package/dist/assets/StatusPill-HY1gCP9c.js +1 -0
  48. package/dist/assets/TrashWorkspace-DtMgxg13.css +1 -0
  49. package/dist/assets/TrashWorkspace-t0lOrFRK.js +1 -0
  50. package/dist/assets/_plugin-vue_export-helper-BK_c4R_m.js +5 -0
  51. package/dist/assets/circle-check-CksZGUB7.js +1 -0
  52. package/dist/assets/database--QlkzG9u.js +1 -0
  53. package/dist/assets/file-U7h4eOhG.js +1 -0
  54. package/dist/assets/globe-TuZP0v6A.js +1 -0
  55. package/dist/assets/history-CIbqkRx3.js +1 -0
  56. package/dist/assets/index-C171UGo4.css +1 -0
  57. package/dist/assets/index-_Tc6Vb8T.js +14 -0
  58. package/dist/assets/layers-BwACvD_U.js +1 -0
  59. package/dist/assets/loader-circle-DYEFqbD4.js +1 -0
  60. package/dist/assets/panel-left-close-Cpq52HZy.js +1 -0
  61. package/dist/assets/plus-7rv1C56N.js +1 -0
  62. package/dist/assets/preload-helper-BB8Wl1va.js +1 -0
  63. package/dist/assets/preload-helper-BxFQpwa9.css +1 -0
  64. package/dist/assets/rotate-ccw-DvjWccJd.js +1 -0
  65. package/dist/assets/save-Dwhm8QNL.js +1 -0
  66. package/dist/assets/schema-helpers-uuDCw8Rb.js +1 -0
  67. package/dist/assets/send-Bs4eROle.js +1 -0
  68. package/dist/assets/smartphone-i429gh5p.js +1 -0
  69. package/dist/assets/trash-2-BbKTm8cC.js +1 -0
  70. package/dist/assets/useCmsState-CDENPbKL.js +1 -0
  71. package/dist/assets/useNodes-D-Vuwq5_.js +1 -0
  72. package/dist/assets/user-DKryA1QU.js +1 -0
  73. package/dist/assets/x-DOWbsdzd.js +1 -0
  74. package/dist/build-seed.js +495 -0
  75. package/dist/{dist-cK3xGnBZ.js → dist-DKRU6nhX.js} +9254 -5762
  76. package/dist/index.html +32 -2
  77. package/dist/index.js +9179 -5689
  78. package/dist/nodemailer-Ccic7tRm-Dw2jwzbm.js +7877 -0
  79. package/dist/nodemailer-Ccic7tRm.js +7908 -0
  80. package/dist/rolldown-runtime-B0aSnxlc.js +20 -0
  81. package/dist/schema-compiler.js +1 -1
  82. package/documentation/FORMS.md +261 -0
  83. package/documentation/SCHEMAS.md +450 -119
  84. package/package.json +14 -6
  85. package/schema.sql +46 -1
  86. package/templates/astro-starter/astro-preview-dev-integration.mjs +83 -0
  87. package/templates/astro-starter/astro.config.mjs +11 -0
  88. package/templates/astro-starter/src/components/blocks/BlockRenderer.astro +17 -0
  89. package/templates/astro-starter/src/components/blocks/Form.astro +313 -0
  90. package/templates/astro-starter/src/components/blocks/HeaderImage.astro +6 -12
  91. package/templates/astro-starter/src/components/blocks/ImageBlock.astro +5 -6
  92. package/templates/astro-starter/src/components/blocks/NodeList.astro +274 -0
  93. package/templates/astro-starter/src/components/global/NavigationMenu.astro +17 -8
  94. package/templates/astro-starter/src/components/ui/KamaImage.astro +13 -5
  95. package/templates/astro-starter/src/layouts/StandardLayout.astro +4 -3
  96. package/templates/astro-starter/src/lib/cms-fetch.ts +22 -0
  97. package/templates/astro-starter/src/lib/cms.ts +18 -9
  98. package/templates/astro-starter/src/lib/media/kama-image-service.ts +15 -4
  99. package/templates/astro-starter/src/lib/media/media-proxy.ts +22 -3
  100. package/templates/astro-starter/src/lib/media/media-url.ts +17 -3
  101. package/templates/astro-starter/src/middleware.ts +199 -71
  102. package/templates/astro-starter/src/pages/[...slug].astro +122 -45
  103. package/templates/astro-starter/src/pages/api/forms/[...path].ts +57 -0
  104. package/templates/astro-starter/src/pages/api/load-nodes.ts +68 -0
  105. package/templates/astro-starter/src/pages/api/partials/node-cards.astro +98 -0
  106. package/templates/astro-starter/src/pages/partials/nav.astro +6 -5
  107. package/templates/kama-worker/index.js +22 -12
  108. package/templates/kama-worker/setup-local-db.mjs +17 -0
  109. package/wrangler.json +19 -0
  110. package/dist/assets/index-C3LzwJjY.css +0 -1
  111. package/dist/assets/index-DhguVxzs.js +0 -164
@@ -26,31 +26,31 @@ if (region.includes("_")) {
26
26
  if (region.includes("_col4")) columnCount = 4;
27
27
  }
28
28
 
29
- // 🎯 Column Config Lookup (Max width, breakpoint widths, sizes)
29
+ // 🎯 Column Config Lookup (Target width, aligned CDN breakpoint widths, sizes)
30
30
  const COLUMN_CONFIGS: Record<
31
31
  number,
32
32
  { targetWidth: number; widths: number[]; sizes: string }
33
33
  > = {
34
34
  1: {
35
35
  targetWidth: 1352,
36
- widths: [768, 1352],
36
+ widths: [768, 1352, 1920, 2560],
37
37
  sizes: "(max-width: 1399px) calc(100vw - 48px), 1352px",
38
38
  },
39
39
  2: {
40
40
  targetWidth: 660,
41
- widths: [400, 660],
41
+ widths: [640, 768, 1024, 1352],
42
42
  sizes:
43
43
  "(max-width: 767px) calc(100vw - 48px), (max-width: 1399px) calc((100vw - 80px) / 2), 660px",
44
44
  },
45
45
  3: {
46
46
  targetWidth: 429,
47
- widths: [300, 429],
47
+ widths: [320, 640, 768, 1024],
48
48
  sizes:
49
49
  "(max-width: 767px) calc(100vw - 48px), (max-width: 1399px) calc((100vw - 112px) / 3), 429px",
50
50
  },
51
51
  4: {
52
52
  targetWidth: 314,
53
- widths: [264, 314],
53
+ widths: [320, 640, 768],
54
54
  sizes:
55
55
  "(max-width: 767px) calc(100vw - 48px), (max-width: 1399px) calc((100vw - 144px) / 4), 314px",
56
56
  },
@@ -67,7 +67,6 @@ const layout = COLUMN_CONFIGS[columnCount] || COLUMN_CONFIGS[1];
67
67
  sizes={layout.sizes}
68
68
  desktopWidths={layout.widths}
69
69
  idealWidth={layout.targetWidth}
70
- maxWidth={layout.targetWidth}
71
70
  class="free-crop-image"
72
71
  loading={isLcp ? "eager" : "lazy"}
73
72
  fetchpriority={isLcp ? "high" : "auto"}
@@ -0,0 +1,274 @@
1
+ ---
2
+ // src/components/blocks/NodeList.astro
3
+ import KamaImage from "@/components/ui/KamaImage.astro";
4
+
5
+ interface Props {
6
+ data: Record<string, any>;
7
+ }
8
+
9
+ const { data } = Astro.props;
10
+ const items = data.initialItems || [];
11
+ const listTitle = data.listTitle || "";
12
+ ---
13
+
14
+ <div class="cms-block node-list-wrapper">
15
+ {listTitle && <h2 class="node-list-title">{listTitle}</h2>}
16
+
17
+ {
18
+ items.length === 0 ? (
19
+ <p class="empty-state">No items found.</p>
20
+ ) : (
21
+ <div class="node-grid" id={`grid-${data.blockId}`}>
22
+ {items.map((item: any) => (
23
+ <article class="node-card">
24
+ <a href={`/${item.slug}`} class="node-card-link">
25
+ {/* 🎯 ARCHITECTURAL FIX: Use KamaImage for initial load optimization */}
26
+ {item.image ? (
27
+ <KamaImage
28
+ image={item.image}
29
+ sizes="(max-width: 639px) 100vw, (max-width: 1023px) 50vw, 33vw"
30
+ desktopWidths={[320, 640, 768, 1024]}
31
+ idealWidth={429}
32
+ loading="lazy"
33
+ />
34
+ ) : (
35
+ <div class="image-placeholder" />
36
+ )}
37
+ <div class="node-card-content">
38
+ <h3 class="node-card-title">{item.title}</h3>
39
+ {item.createdAt && (
40
+ <time datetime={item.createdAt} class="node-card-date">
41
+ {new Date(item.createdAt).toLocaleDateString("en-GB", {
42
+ day: "numeric",
43
+ month: "short",
44
+ year: "numeric",
45
+ })}
46
+ </time>
47
+ )}
48
+ {item.excerpt && (
49
+ <p class="node-card-excerpt">{item.excerpt}</p>
50
+ )}
51
+ </div>
52
+ </a>
53
+ </article>
54
+ ))}
55
+ </div>
56
+ )
57
+ }
58
+
59
+ {
60
+ data.loadMoreUrl && (
61
+ <div class="load-more-container">
62
+ <button
63
+ class="load-more-btn"
64
+ data-url={data.loadMoreUrl}
65
+ data-target={`grid-${data.blockId}`}
66
+ >
67
+ Load More
68
+ </button>
69
+ </div>
70
+ )
71
+ }
72
+ </div>
73
+
74
+ <style is:global>
75
+ .node-list-wrapper {
76
+ margin: 2rem 0;
77
+ }
78
+
79
+ .node-list-title {
80
+ font-size: 1.5rem;
81
+ font-weight: 700;
82
+ margin-bottom: 1.5rem;
83
+ color: #1e293b;
84
+ }
85
+
86
+ .node-list-wrapper .empty-state {
87
+ color: #64748b;
88
+ font-style: italic;
89
+ }
90
+
91
+ .node-grid {
92
+ display: grid;
93
+ grid-template-columns: repeat(1, 1fr);
94
+ gap: 1.5rem;
95
+ }
96
+
97
+ @media (min-width: 640px) {
98
+ .node-grid {
99
+ grid-template-columns: repeat(2, 1fr);
100
+ }
101
+ }
102
+
103
+ @media (min-width: 1024px) {
104
+ .node-grid {
105
+ grid-template-columns: repeat(3, 1fr);
106
+ }
107
+ }
108
+
109
+ .node-card {
110
+ border: 1px solid #e2e8f0;
111
+ border-radius: 8px;
112
+ overflow: hidden;
113
+ background: #fff;
114
+ transition:
115
+ transform 0.2s ease,
116
+ box-shadow 0.2s ease;
117
+ }
118
+
119
+ .node-card:hover {
120
+ transform: translateY(-2px);
121
+ box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.1);
122
+ }
123
+
124
+ .node-card-link {
125
+ text-decoration: none;
126
+ color: inherit;
127
+ display: flex;
128
+ flex-direction: column;
129
+ height: 100%;
130
+ }
131
+
132
+ /* 🎯 Because of is:global, this styling will automatically apply to <KamaImage> outputs! */
133
+ .node-card img,
134
+ .node-card .image-placeholder {
135
+ width: 100%;
136
+ height: auto; /* 🎯 FIX: Allows tall images to display their natural height */
137
+ object-fit: cover;
138
+ background: #f1f5f9;
139
+ }
140
+
141
+ .node-card .image-placeholder {
142
+ aspect-ratio: 16 / 9; /* Keep the placeholder a rectangle if there is no image at all */
143
+ }
144
+ .node-card-content {
145
+ padding: 1.25rem;
146
+ display: flex;
147
+ flex-direction: column;
148
+ flex-grow: 1;
149
+ }
150
+
151
+ .node-card-title {
152
+ font-size: 1.125rem;
153
+ font-weight: 600;
154
+ margin: 0 0 0.5rem 0;
155
+ color: #0f172a;
156
+ line-height: 1.4;
157
+ }
158
+
159
+ .node-card-date {
160
+ font-size: 0.875rem;
161
+ color: #64748b;
162
+ margin-bottom: 0.75rem;
163
+ }
164
+
165
+ .node-card-excerpt {
166
+ font-size: 0.9375rem;
167
+ color: #475569;
168
+ margin: 0;
169
+ line-height: 1.5;
170
+ display: -webkit-box;
171
+ -webkit-line-clamp: 3;
172
+ -webkit-box-orient: vertical;
173
+ overflow: hidden;
174
+ }
175
+
176
+ .load-more-container {
177
+ margin-top: 2rem;
178
+ text-align: center;
179
+ }
180
+
181
+ .load-more-btn {
182
+ padding: 0.75rem 1.5rem;
183
+ background: #0f172a;
184
+ color: #fff;
185
+ border: none;
186
+ border-radius: 6px;
187
+ font-weight: 600;
188
+ cursor: pointer;
189
+ transition: background 0.2s;
190
+ }
191
+
192
+ .load-more-btn:hover {
193
+ background: #334155;
194
+ }
195
+ </style>
196
+
197
+ <script>
198
+ function initLoadMoreButtons() {
199
+ const buttons = document.querySelectorAll(".load-more-btn:not(.is-bound)");
200
+
201
+ buttons.forEach(btn => {
202
+ btn.classList.add("is-bound");
203
+
204
+ btn.addEventListener("click", async e => {
205
+ const targetBtn = e.currentTarget as HTMLButtonElement;
206
+ const urlString = targetBtn.getAttribute("data-url");
207
+ const targetId = targetBtn.getAttribute("data-target");
208
+
209
+ if (!urlString || !targetId) return;
210
+
211
+ const grid = document.getElementById(targetId);
212
+ if (!grid) return;
213
+
214
+ const urlObj = new URL(urlString, window.location.origin);
215
+ // 🎯 ARCHITECTURAL FIX: Route to the new HTML Partial Endpoint
216
+ const proxyUrl = `/api/partials/node-cards${urlObj.search}`;
217
+
218
+ targetBtn.textContent = "Loading...";
219
+ targetBtn.disabled = true;
220
+
221
+ try {
222
+ const res = await fetch(proxyUrl);
223
+
224
+ if (!res.ok) {
225
+ throw new Error(`HTTP error! status: ${res.status}`);
226
+ }
227
+
228
+ // 1. Read metadata from headers sent by our partial endpoint
229
+ const rawCountStr = res.headers.get("X-Consumed-Rows");
230
+ const limitStr = res.headers.get("X-Limit");
231
+ const consumedRows = parseInt(rawCountStr || "0", 10);
232
+ const limit = parseInt(limitStr || "12", 10);
233
+
234
+ // 2. Extract and render the raw HTML
235
+ const htmlSnippet = await res.text();
236
+
237
+ if (htmlSnippet.trim().length > 0) {
238
+ grid.insertAdjacentHTML("beforeend", htmlSnippet);
239
+ }
240
+
241
+ // 3. Handle Pagination
242
+ if (consumedRows >= limit && limit > 0) {
243
+ const currentOffset = parseInt(
244
+ urlObj.searchParams.get("offset") || "0",
245
+ 10,
246
+ );
247
+ urlObj.searchParams.set(
248
+ "offset",
249
+ (currentOffset + limit).toString(),
250
+ );
251
+
252
+ targetBtn.setAttribute("data-url", urlObj.pathname + urlObj.search);
253
+ targetBtn.textContent = "Load More";
254
+ targetBtn.disabled = false;
255
+ } else {
256
+ if (targetBtn.parentElement)
257
+ targetBtn.parentElement.style.display = "none";
258
+ }
259
+ } catch (err) {
260
+ console.error("Failed to load more items:", err);
261
+ targetBtn.textContent = "Error. Try again";
262
+ targetBtn.disabled = false;
263
+ }
264
+ });
265
+ });
266
+ }
267
+
268
+ if (document.readyState === "loading") {
269
+ document.addEventListener("DOMContentLoaded", initLoadMoreButtons);
270
+ } else {
271
+ initLoadMoreButtons();
272
+ }
273
+ document.addEventListener("astro:page-load", initLoadMoreButtons);
274
+ </script>
@@ -1,6 +1,6 @@
1
1
  ---
2
2
  // src/components/global/NavigationMenu.astro
3
- import type { TreeNode } from "@/lib/cms";
3
+ import { getTreeNodeMenuTitle, type TreeNode } from "@/lib/cms";
4
4
 
5
5
  export interface Props {
6
6
  tree?: TreeNode[];
@@ -23,7 +23,8 @@ const rootNode =
23
23
 
24
24
  // 🎯 FIX: If rootNode has children, display those children as top-level menu items.
25
25
  // If not, filter out the root node by ID AND path.
26
- const topLevelNavItems =
26
+ // ✨ NEW: Filter out nodes where notInMenu is true
27
+ const rawTopLevelItems =
27
28
  rootNode?.children && rootNode.children.length > 0
28
29
  ? rootNode.children
29
30
  : tree.filter(
@@ -34,6 +35,10 @@ const topLevelNavItems =
34
35
  item.path !== "",
35
36
  );
36
37
 
38
+ const topLevelNavItems = rawTopLevelItems.filter(
39
+ item => !(item as any).notInMenu,
40
+ );
41
+
37
42
  const isPathActive = (itemPath?: string) => {
38
43
  const normItem = (itemPath || "").replace(/\/$/, "") || "/";
39
44
  if (normItem === "/") return currentPath === "/";
@@ -62,7 +67,11 @@ const isExactActive = (itemPath?: string) => {
62
67
  <ul class="nav-list">
63
68
  {
64
69
  topLevelNavItems.map(item => {
65
- const hasChildren = item.children && item.children.length > 0;
70
+ const menuTitle = getTreeNodeMenuTitle(item);
71
+ // ✨ NEW: Also filter children for notInMenu
72
+ const visibleChildren =
73
+ item.children?.filter(child => !(child as any).notInMenu) || [];
74
+ const hasChildren = visibleChildren.length > 0;
66
75
  const isParentActive = isPathActive(item.path);
67
76
 
68
77
  if (hasChildren) {
@@ -76,7 +85,7 @@ const isExactActive = (itemPath?: string) => {
76
85
  { active: isParentActive },
77
86
  ]}
78
87
  >
79
- <span>{item.title}</span>
88
+ <span>{menuTitle}</span>
80
89
  <span class="indicator">▼</span>
81
90
  </summary>
82
91
  <div class="submenu-container">
@@ -90,10 +99,10 @@ const isExactActive = (itemPath?: string) => {
90
99
  { active: isExactActive(item.path) },
91
100
  ]}
92
101
  >
93
- {item.title} Overview
102
+ {menuTitle} Overview
94
103
  </a>
95
104
  </li>
96
- {item.children?.map(child => (
105
+ {visibleChildren.map(child => (
97
106
  <li>
98
107
  <a
99
108
  href={child.path}
@@ -102,7 +111,7 @@ const isExactActive = (itemPath?: string) => {
102
111
  { active: isExactActive(child.path) },
103
112
  ]}
104
113
  >
105
- {child.title}
114
+ {getTreeNodeMenuTitle(child)}
106
115
  </a>
107
116
  </li>
108
117
  ))}
@@ -119,7 +128,7 @@ const isExactActive = (itemPath?: string) => {
119
128
  href={item.path}
120
129
  class:list={["nav-button", { active: isExactActive(item.path) }]}
121
130
  >
122
- {item.title}
131
+ {menuTitle}
123
132
  </a>
124
133
  </li>
125
134
  );
@@ -20,7 +20,7 @@ interface Props {
20
20
  const {
21
21
  image = {},
22
22
  sizes = "100vw",
23
- desktopWidths = [768, 1352],
23
+ desktopWidths = [768, 1352, 1920, 2560],
24
24
  idealWidth = 1352,
25
25
  class: className = "",
26
26
  loading = "lazy",
@@ -90,18 +90,26 @@ function buildAgnosticSrcset(
90
90
  .join(", ");
91
91
  }
92
92
 
93
- // Generate srcsets only for raster images
93
+ // 🎯 High-DPI / Retina Optimization:
94
+ // - Mobile: Includes 320, 640, 768 (covers 2x and 3x Retina mobile displays)
95
+ // - Tablet: Includes 768, 1024, 1352 (covers iPad Pro Retina density)
96
+ // - Desktop: Uses desktopWidths (defaults to 768, 1352, 1920, 2560 for 1440p and 4K)
94
97
  const mobileSrcset =
95
- !isSvg && rawMobileUrl ? buildAgnosticSrcset(rawMobileUrl, [400, 768]) : null;
98
+ !isSvg && rawMobileUrl
99
+ ? buildAgnosticSrcset(rawMobileUrl, [320, 640, 768])
100
+ : null;
96
101
 
97
102
  const tabletSrcset =
98
103
  !isSvg && rawTabletUrl
99
- ? buildAgnosticSrcset(rawTabletUrl, [768, 1024])
104
+ ? buildAgnosticSrcset(rawTabletUrl, [768, 1024, 1352])
100
105
  : null;
101
106
 
102
107
  const desktopSrcset =
103
108
  !isSvg && rawDesktopUrl
104
- ? buildAgnosticSrcset(rawDesktopUrl, desktopWidths)
109
+ ? buildAgnosticSrcset(
110
+ rawDesktopUrl,
111
+ desktopWidths.length ? desktopWidths : [768, 1352, 1920, 2560],
112
+ )
105
113
  : null;
106
114
 
107
115
  const fallbackUrl =
@@ -28,10 +28,11 @@ const {
28
28
  language,
29
29
  } = Astro.props;
30
30
 
31
- // 🎯 Language Cascade
31
+ // 🎯 Language Cascade: explicit prop -> node language -> fallback undefined
32
+ // (MetaHead will resolve channel.defaultLanguage if this remains undefined)
32
33
  const pageLang = language || node?.language || undefined;
33
34
 
34
- // 🎯 Extract the footer blocks the backend already thoughtfully provided
35
+ // 🎯 FIX: Extract the footer blocks from the payload again
35
36
  const footerBlocks = content?.footer || [];
36
37
  ---
37
38
 
@@ -56,7 +57,7 @@ const footerBlocks = content?.footer || [];
56
57
  </div>
57
58
  </main>
58
59
 
59
- <!-- 🎯 Pass the blocks and content map directly -->
60
+ {/* 🎯 FIX: Pass the blocks and contentMap into the Footer */}
60
61
  <Footer blocks={footerBlocks} contentMap={content} />
61
62
  </body>
62
63
  </html>
@@ -0,0 +1,22 @@
1
+ export async function fetchCmsRequest(
2
+ request: Request,
3
+ cmsWorker: { fetch: (request: Request) => Promise<Response> } | undefined,
4
+ ): Promise<Response> {
5
+ const requestUrl = new URL(request.url);
6
+ const isPreviewRequest = requestUrl.searchParams.get("preview") === "true"
7
+ || requestUrl.searchParams.has("revisionId");
8
+ if (isPreviewRequest) return fetch(request);
9
+ if (!cmsWorker) return fetch(request);
10
+
11
+ const fallbackRequest = request.clone();
12
+ const response = await cmsWorker.fetch(request);
13
+ if (!import.meta.env.DEV || response.status !== 503) return response;
14
+
15
+ const errorText = await response.clone().text();
16
+ if (!/^Worker ".+" not found\. Make sure it is running locally\.$/.test(errorText.trim())) {
17
+ return response;
18
+ }
19
+
20
+ const localUrl = new URL(`${requestUrl.pathname}${requestUrl.search}`, "http://127.0.0.1:8787");
21
+ return fetch(new Request(localUrl, fallbackRequest));
22
+ }
@@ -5,6 +5,7 @@ export interface TreeNode {
5
5
  treeNodeId: number;
6
6
  parentId: number | null;
7
7
  title: string;
8
+ menuTitle?: string;
8
9
  slug: string;
9
10
  path: string;
10
11
  nodeType: string;
@@ -16,6 +17,12 @@ export interface TreeNode {
16
17
  [key: string]: any;
17
18
  }
18
19
 
20
+ export function getTreeNodeMenuTitle(node: Pick<TreeNode, 'title' | 'menuTitle'>): string {
21
+ return typeof node.menuTitle === 'string' && node.menuTitle.trim()
22
+ ? node.menuTitle.trim()
23
+ : node.title;
24
+ }
25
+
19
26
  export interface ContentBlock {
20
27
  instanceId: number;
21
28
  componentId: string;
@@ -93,6 +100,14 @@ export function getTreeId(): string {
93
100
  return import.meta.env.PUBLIC_TREE_ID || 'navigation';
94
101
  }
95
102
 
103
+ // 🎯 Safely resolve global authorization header for default CMS fetches
104
+ function getAuthHeaders(): Record<string, string> {
105
+ const secret = import.meta.env.FRONTEND_API_SECRET;
106
+ const headers: Record<string, string> = { Accept: 'application/json' };
107
+ if (secret) headers['Authorization'] = `Bearer ${secret}`;
108
+ return headers;
109
+ }
110
+
96
111
  /**
97
112
  * Fetch channel metadata by key/ID.
98
113
  * Serves global site branding, logos, favicons, and schema-defined public fields.
@@ -106,9 +121,7 @@ export async function getChannel(
106
121
 
107
122
  try {
108
123
  const res = await customFetch(requestUrl, {
109
- headers: {
110
- Accept: 'application/json',
111
- },
124
+ headers: getAuthHeaders(),
112
125
  });
113
126
 
114
127
  if (!res.ok) return null;
@@ -140,9 +153,7 @@ export async function getTree(
140
153
 
141
154
  try {
142
155
  const res = await customFetch(requestUrl, {
143
- headers: {
144
- Accept: 'application/json',
145
- },
156
+ headers: getAuthHeaders(),
146
157
  });
147
158
 
148
159
  if (!res.ok) return [];
@@ -179,9 +190,7 @@ export async function getNodeByPath(
179
190
 
180
191
  try {
181
192
  const res = await customFetch(requestUrl, {
182
- headers: {
183
- Accept: 'application/json',
184
- },
193
+ headers: getAuthHeaders(),
185
194
  });
186
195
 
187
196
  if (!res.ok) return null;
@@ -28,10 +28,21 @@ const kamaImageService: LocalImageService = {
28
28
 
29
29
  const url = new URL(src, 'http://localhost');
30
30
 
31
- if (options.width) url.searchParams.set('w', Math.round(options.width).toString());
32
- if (options.height) url.searchParams.set('h', Math.round(options.height).toString());
33
- if (options.quality) url.searchParams.set('q', options.quality.toString());
34
- if (options.format) url.searchParams.set('f', options.format.toString());
31
+ // 🎯 Pass width if defined (snapped on backend by assets.ts)
32
+ if (options.width && !isNaN(options.width)) {
33
+ url.searchParams.set('w', Math.round(options.width).toString());
34
+ }
35
+
36
+ // 🎯 Pass height only if explicitly provided to maintain intrinsic aspect ratios
37
+ if (options.height && !isNaN(options.height)) {
38
+ url.searchParams.set('h', Math.round(options.height).toString());
39
+ }
40
+
41
+ // 🎯 Default quality to 75 if unsupplied
42
+ url.searchParams.set('q', (options.quality || 75).toString());
43
+
44
+ // 🎯 Default format to 'auto' for backend WebP/AVIF negotiation
45
+ url.searchParams.set('f', options.format ? options.format.toString() : 'auto');
35
46
 
36
47
  return src.startsWith('http') ? url.toString() : (url.pathname + url.search);
37
48
  } catch (e) {
@@ -28,12 +28,31 @@ export async function handleMediaProxy({ request, params, url, locals }: APICont
28
28
  // 🎯 Detect if Astro is requesting a resized variant
29
29
  const hasResizeParams = url.searchParams.has('w') || url.searchParams.has('h') || url.searchParams.has('q') || url.searchParams.has('f');
30
30
 
31
+ // 🎯 Resolve Negotiated Format for Edge Cache Key
32
+ const acceptHeader = request.headers.get('Accept') || '';
33
+ const fParam = url.searchParams.get('f');
34
+ let resolvedFormat = fParam && fParam !== 'auto' ? fParam : '';
35
+
36
+ if (!resolvedFormat && hasResizeParams) {
37
+ if (acceptHeader.includes('image/avif')) resolvedFormat = 'avif';
38
+ else if (acceptHeader.includes('image/webp')) resolvedFormat = 'webp';
39
+ }
40
+
41
+ // 🎯 Construct a safe Cache Key that accounts for format negotiation
42
+ let cacheKeyUrl = request.url;
43
+ if (hasResizeParams && resolvedFormat && !fParam) {
44
+ const cacheUrlObj = new URL(cacheKeyUrl);
45
+ cacheUrlObj.searchParams.set('_resolvedFormat', resolvedFormat);
46
+ cacheKeyUrl = cacheUrlObj.toString();
47
+ }
48
+ const cacheKey = new Request(cacheKeyUrl, request);
49
+
31
50
  // 1. Cloudflare Edge Cache API
32
51
  let edgeCache: Cache | null = null;
33
52
  try {
34
53
  if (typeof caches !== "undefined" && caches.default) {
35
54
  edgeCache = caches.default;
36
- const cachedResponse = await edgeCache.match(request);
55
+ const cachedResponse = await edgeCache.match(cacheKey);
37
56
  if (cachedResponse) return cachedResponse;
38
57
  }
39
58
  } catch (err) {
@@ -67,7 +86,7 @@ export async function handleMediaProxy({ request, params, url, locals }: APICont
67
86
  const r2Response = new Response(r2Object.body, { status: 200, headers });
68
87
 
69
88
  if (edgeCache) {
70
- const cachePromise = edgeCache.put(request, r2Response.clone());
89
+ const cachePromise = edgeCache.put(cacheKey, r2Response.clone());
71
90
  if (cfContext?.waitUntil) cfContext.waitUntil(cachePromise);
72
91
  else cachePromise.catch(e => console.warn(e));
73
92
  }
@@ -112,7 +131,7 @@ export async function handleMediaProxy({ request, params, url, locals }: APICont
112
131
  });
113
132
 
114
133
  if (edgeCache) {
115
- const cachePromise = edgeCache.put(request, proxyResponse.clone());
134
+ const cachePromise = edgeCache.put(cacheKey, proxyResponse.clone());
116
135
  if (cfContext?.waitUntil) cfContext.waitUntil(cachePromise);
117
136
  else cachePromise.catch(e => console.warn(e));
118
137
  }
@@ -1,11 +1,22 @@
1
1
  // src/lib/media/media-url.ts
2
2
 
3
+ /**
4
+ * Normalizes absolute CMS URLs into clean relative /media/... paths.
5
+ * Ensures CSP compliance by routing requests through the Astro frontend proxy.
6
+ */
3
7
  export function toRelativeMediaPath(rawUrl: string): string {
4
8
  if (!rawUrl) return "";
5
9
 
6
- let clean = String(rawUrl);
7
- clean = clean.replace(/^https?:\/\/[^/]+/, "");
8
- clean = clean.split("?")[0].split("#")[0];
10
+ let clean = String(rawUrl).trim();
11
+
12
+ try {
13
+ // Parse absolute or relative URLs safely using a dummy origin fallback
14
+ const urlObj = new URL(clean, "http://localhost");
15
+ clean = urlObj.pathname;
16
+ } catch {
17
+ // Fallback cleanup for malformed strings
18
+ clean = clean.replace(/^https?:\/\/[^/]+/, "").split("?")[0].split("#")[0];
19
+ }
9
20
 
10
21
  const mediaIndex = clean.indexOf("/media/");
11
22
  if (mediaIndex !== -1) {
@@ -26,6 +37,9 @@ export function isSvgImage(urlOrMime: string): boolean {
26
37
  return lower.endsWith('.svg') || lower.includes('image/svg+xml') || lower.includes('.svg?');
27
38
  }
28
39
 
40
+ /**
41
+ * Constructs an agnostic /media/... URL with standard optimization query parameters.
42
+ */
29
43
  export function buildAgnosticImageUrl(
30
44
  url: string,
31
45
  width: number,